From a1a9a614cb396922ca4a7a63f633aa1463c84e86 Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Wed, 23 Oct 2024 15:20:22 +0200 Subject: [PATCH 1/2] [BUGFIX] Revert broken support for multiple comments This reverts e4c66f62c5df3f53f48d82cb30b20b3007af7574 (#672), which broke comment parsing in strict mode. We'll need to re-implement support for multiple comments later in a way that does not break the existing comment parsing. --- CHANGELOG.md | 2 +- src/Rule/Rule.php | 4 +--- tests/ParserTest.php | 16 ---------------- tests/RuleSet/DeclarationBlockTest.php | 2 -- 4 files changed, 2 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7eef20b7..ca3d06c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,8 +42,8 @@ Please also have a look at our ### Fixed +- Revert broken support for multiple comments (#740) - Fix type errors in PHP strict mode (#664) -- 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) diff --git a/src/Rule/Rule.php b/src/Rule/Rule.php index e2a483ce..9770a0ad 100644 --- a/src/Rule/Rule.php +++ b/src/Rule/Rule.php @@ -108,9 +108,7 @@ public static function parse(ParserState $oParserState): Rule $oParserState->consume(';'); } - while (\preg_match('/\\s/isSu', $oParserState->peek()) === 1) { - $oParserState->consume(1); - } + $oParserState->consumeWhiteSpace(); return $oRule; } diff --git a/tests/ParserTest.php b/tests/ParserTest.php index 8bbbd69d..419b4a8f 100644 --- a/tests/ParserTest.php +++ b/tests/ParserTest.php @@ -1171,22 +1171,6 @@ public function flatCommentExtractingOneComment(): 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;}'); - $document = $parser->parse(); - $contents = $document->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 diff --git a/tests/RuleSet/DeclarationBlockTest.php b/tests/RuleSet/DeclarationBlockTest.php index 871ed194..15430ae9 100644 --- a/tests/RuleSet/DeclarationBlockTest.php +++ b/tests/RuleSet/DeclarationBlockTest.php @@ -467,8 +467,6 @@ public function canRemoveCommentsFromRulesUsingStrictParsing( string $cssWithComments, string $cssWithoutComments ): void { - self::markTestSkipped('This currently crashes, and we need to fix it.'); - $parserSettings = ParserSettings::create()->withLenientParsing(false); $document = (new Parser($cssWithComments, $parserSettings))->parse(); From 9bfa67fbdb98baec466df6da131882a5c52349b9 Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Wed, 23 Oct 2024 18:22:08 +0200 Subject: [PATCH 2/2] Add changes suggested in code review --- CHANGELOG.md | 1 - tests/ParserTest.php | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ca3d06c6..a0fabf7d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,7 +42,6 @@ Please also have a look at our ### Fixed -- Revert broken support for multiple comments (#740) - Fix type errors in PHP strict mode (#664) - Fix undefined local variable in `CalcFunction::parse()` (#593) - Fix PHP notice caused by parsing invalid color values having less than 6 diff --git a/tests/ParserTest.php b/tests/ParserTest.php index 419b4a8f..dcbcc1c0 100644 --- a/tests/ParserTest.php +++ b/tests/ParserTest.php @@ -1172,6 +1172,25 @@ public function flatCommentExtractingOneComment(): void self::assertSame('Find Me!', $comments[0]->getComment()); } + /** + * @test + */ + public function flatCommentExtractingTwoComments(): void + { + self::markTestSkipped('This is currently broken.'); + + $parser = new Parser('div {/*Find Me!*/left:10px; /*Find Me Too!*/text-align:left;}'); + $document = $parser->parse(); + $contents = $document->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 */