diff --git a/CHANGELOG.md b/CHANGELOG.md index ed390901..e4386c42 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,6 +46,7 @@ This project adheres to [Semantic Versioning](https://semver.org/). ### Fixed +- Fix comment parsing to support multiple comments (#672) - Fix undefined local variable in `CalcFunction::parse()` (#593) - Fix PHP notice caused by parsing invalid color values having less than 6 characters (#485) - Fix (regression) failure to parse at-rules with strict parsing (#456) diff --git a/src/Rule/Rule.php b/src/Rule/Rule.php index ca9f380c..9514be29 100644 --- a/src/Rule/Rule.php +++ b/src/Rule/Rule.php @@ -105,7 +105,10 @@ public static function parse(ParserState $oParserState): Rule while ($oParserState->comes(';')) { $oParserState->consume(';'); } - $oParserState->consumeWhiteSpace(); + + while (\preg_match('/\\s/isSu', $oParserState->peek()) === 1) { + $oParserState->consume(1); + } return $oRule; } diff --git a/tests/ParserTest.php b/tests/ParserTest.php index 2c1c7287..dde4aaca 100644 --- a/tests/ParserTest.php +++ b/tests/ParserTest.php @@ -1159,7 +1159,7 @@ public function commentExtracting(): void /** * @test */ - public function flatCommentExtracting(): void + public function flatCommentExtractingOneComment(): void { $parser = new Parser('div {/*Find Me!*/left:10px; text-align:left;}'); $doc = $parser->parse(); @@ -1169,6 +1169,22 @@ public function flatCommentExtracting(): void self::assertCount(1, $comments); self::assertSame('Find Me!', $comments[0]->getComment()); } + /** + * @test + */ + public function flatCommentExtractingTwoComments(): void + { + $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