Skip to content

Commit d88d6da

Browse files
committed
Fix comments being omitted in the middle of a rule
1 parent a80a97d commit d88d6da

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

Diff for: lib/Sabberworm/CSS/Parsing/ParserState.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,15 @@ public function parseCharacter($bIsForIdentifier) {
112112
return null;
113113
}
114114

115-
public function consumeWhiteSpace() {
115+
public function consumeWhiteSpace($consumeComments = true) {
116116
$comments = array();
117117
do {
118118
while (preg_match('/\\s/isSu', $this->peek()) === 1) {
119119
$this->consume(1);
120120
}
121+
if (!$consumeComments) {
122+
return;
123+
}
121124
if($this->oParserSettings->bLenientParsing) {
122125
try {
123126
$oComment = $this->consumeComment();

Diff for: lib/Sabberworm/CSS/Rule/Rule.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public static function parse(ParserState $oParserState) {
5656
while ($oParserState->comes(';')) {
5757
$oParserState->consume(';');
5858
}
59-
$oParserState->consumeWhiteSpace();
59+
$oParserState->consumeWhiteSpace(false);
6060

6161
return $oRule;
6262
}

Diff for: tests/Sabberworm/CSS/ParserTest.php

+10
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,16 @@ function testFlatCommentExtracting() {
733733
$this->assertEquals("Find Me!", $comments[0]->getComment());
734734
}
735735

736+
function testInnerCommentExtracting() {
737+
$parser = new Parser('div {left:10px;/*Find Me!*/text-align:left;}');
738+
$doc = $parser->parse();
739+
$contents = $doc->getContents();
740+
$divRules = $contents[0]->getRules();
741+
$comments = $divRules[1]->getComments();
742+
$this->assertCount(1, $comments);
743+
$this->assertEquals("Find Me!", $comments[0]->getComment());
744+
}
745+
736746
function testTopLevelCommentExtracting() {
737747
$parser = new Parser('/*Find Me!*/div {left:10px; text-align:left;}');
738748
$doc = $parser->parse();

0 commit comments

Comments
 (0)