diff --git a/src/CSSList/CSSList.php b/src/CSSList/CSSList.php index 946740a4..857b38d8 100644 --- a/src/CSSList/CSSList.php +++ b/src/CSSList/CSSList.php @@ -89,7 +89,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/src/Parsing/ParserState.php b/src/Parsing/ParserState.php index 2dda8c84..f40e372e 100644 --- a/src/Parsing/ParserState.php +++ b/src/Parsing/ParserState.php @@ -2,6 +2,7 @@ namespace Sabberworm\CSS\Parsing; +use phpDocumentor\Reflection\Types\Boolean; use Sabberworm\CSS\Comment\Comment; use Sabberworm\CSS\Settings; @@ -197,18 +198,24 @@ public function parseCharacter($bIsForIdentifier) } /** + * @param bool $consumeComments defaults to true * @return array|void * * @throws UnexpectedEOFException * @throws UnexpectedTokenException */ - public function consumeWhiteSpace() + public function consumeWhiteSpace($consumeComments = true) { $comments = []; 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/src/Rule/Rule.php b/src/Rule/Rule.php index c1ea6df7..63cc4057 100644 --- a/src/Rule/Rule.php +++ b/src/Rule/Rule.php @@ -106,7 +106,7 @@ public static function parse(ParserState $oParserState) while ($oParserState->comes(';')) { $oParserState->consume(';'); } - $oParserState->consumeWhiteSpace(); + $oParserState->consumeWhiteSpace(false); return $oRule; } diff --git a/tests/ParserTest.php b/tests/ParserTest.php index ab247c3d..6136a3da 100644 --- a/tests/ParserTest.php +++ b/tests/ParserTest.php @@ -1120,6 +1120,20 @@ public function flatCommentExtracting() self::assertSame("Find Me!", $comments[0]->getComment()); } + /** + * @test + */ + public function innerCommentExtracting() + { + $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(); + self::assertCount(1, $comments); + self::assertEquals("Find Me!", $comments[0]->getComment()); + } + /** * @test */