Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX] Fix comment parsing to support multiple comments #672

Merged
merged 1 commit into from
Aug 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion src/Rule/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
18 changes: 17 additions & 1 deletion tests/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
Expand Down