diff --git a/CHANGELOG.md b/CHANGELOG.md index d1837d0b..cc91e719 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,8 @@ This project adheres to [Semantic Versioning](https://semver.org/). ### Fixed +- Fix comment parsing to support multiple comments (#671) + ## 8.6.0 ### Added diff --git a/src/Rule/Rule.php b/src/Rule/Rule.php index fc00c880..9b693ece 100644 --- a/src/Rule/Rule.php +++ b/src/Rule/Rule.php @@ -107,7 +107,12 @@ public static function parse(ParserState $oParserState) while ($oParserState->comes(';')) { $oParserState->consume(';'); } - $oParserState->consumeWhiteSpace(); + + // NOTE: This is a backport to fix comment parsing to support multiple + // comments. This will be rectified in version 9.0.0. + while (preg_match('/\\s/isSu', $oParserState->peek()) === 1) { + $oParserState->consume(1); + } return $oRule; } diff --git a/tests/ParserTest.php b/tests/ParserTest.php index a48ac0e7..036fd033 100644 --- a/tests/ParserTest.php +++ b/tests/ParserTest.php @@ -1162,7 +1162,7 @@ public function commentExtracting() /** * @test */ - public function flatCommentExtracting() + public function flatCommentExtractingOneComment() { $parser = new Parser('div {/*Find Me!*/left:10px; text-align:left;}'); $doc = $parser->parse(); @@ -1172,6 +1172,22 @@ public function flatCommentExtracting() self::assertCount(1, $comments); self::assertSame("Find Me!", $comments[0]->getComment()); } + /** + * @test + */ + public function flatCommentExtractingTwoComments() + { + $parser = new Parser('div {/*Find Me!*/left:10px; /*Find Me Too!*/text-align:left;}'); + $doc = $parser->parse(); + $contents = $doc->getContents(); + $divRules = $contents[0]->getRules(); + $rule1Comments = $divRules[0]->getComments(); + $rule2Comments = $divRules[1]->getComments(); + self::assertCount(1, $rule1Comments); + self::assertCount(1, $rule2Comments); + self::assertEquals('Find Me!', $rule1Comments[0]->getComment()); + self::assertEquals('Find Me Too!', $rule2Comments[0]->getComment()); + } /** * @test