diff --git a/lib/Sabberworm/CSS/CSSList/CSSList.php b/lib/Sabberworm/CSS/CSSList/CSSList.php index aebefffc..ae47b78c 100644 --- a/lib/Sabberworm/CSS/CSSList/CSSList.php +++ b/lib/Sabberworm/CSS/CSSList/CSSList.php @@ -62,7 +62,7 @@ public static function parseList(ParserState $oParserState, CSSList $oList) { $oListItem->setComments($comments); $oList->append($oListItem); } - $oParserState->consumeWhiteSpace(); + $oParserState->consumeWhiteSpace(false); } if(!$bIsRoot && !$bLenientParsing) { throw new SourceException("Unexpected end of document", $oParserState->currentLine()); diff --git a/lib/Sabberworm/CSS/Parsing/ParserState.php b/lib/Sabberworm/CSS/Parsing/ParserState.php index ad79820a..e39b9491 100644 --- a/lib/Sabberworm/CSS/Parsing/ParserState.php +++ b/lib/Sabberworm/CSS/Parsing/ParserState.php @@ -112,12 +112,15 @@ public function parseCharacter($bIsForIdentifier) { return null; } - public function consumeWhiteSpace() { + public function consumeWhiteSpace($consumeComments = true) { $comments = array(); do { while (preg_match('/\\s/isSu', $this->peek()) === 1) { $this->consume(1); } + if (!$consumeComments) { + return; + } if($this->oParserSettings->bLenientParsing) { try { $oComment = $this->consumeComment(); diff --git a/lib/Sabberworm/CSS/Rule/Rule.php b/lib/Sabberworm/CSS/Rule/Rule.php index 3fa031bd..f019dea7 100644 --- a/lib/Sabberworm/CSS/Rule/Rule.php +++ b/lib/Sabberworm/CSS/Rule/Rule.php @@ -56,7 +56,7 @@ public static function parse(ParserState $oParserState) { while ($oParserState->comes(';')) { $oParserState->consume(';'); } - $oParserState->consumeWhiteSpace(); + $oParserState->consumeWhiteSpace(false); return $oRule; } diff --git a/tests/Sabberworm/CSS/ParserTest.php b/tests/Sabberworm/CSS/ParserTest.php index ea34f2e7..40613f1f 100644 --- a/tests/Sabberworm/CSS/ParserTest.php +++ b/tests/Sabberworm/CSS/ParserTest.php @@ -733,6 +733,16 @@ function testFlatCommentExtracting() { $this->assertEquals("Find Me!", $comments[0]->getComment()); } + function testInnerCommentExtracting() { + $parser = new Parser('div {left:10px;/*Find Me!*/text-align:left;}'); + $doc = $parser->parse(); + $contents = $doc->getContents(); + $divRules = $contents[0]->getRules(); + $comments = $divRules[1]->getComments(); + $this->assertCount(1, $comments); + $this->assertEquals("Find Me!", $comments[0]->getComment()); + } + function testTopLevelCommentExtracting() { $parser = new Parser('/*Find Me!*/div {left:10px; text-align:left;}'); $doc = $parser->parse();