From 3b9b115e90f9ae6d41f5eec480cfd1a22b36dbe6 Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Tue, 25 Feb 2025 11:47:46 +0100 Subject: [PATCH 1/3] [TASK] Remove the IE hack in `Rule` --- CHANGELOG.md | 1 + config/phpstan-baseline.neon | 12 ------------ src/Rule/Rule.php | 34 +--------------------------------- tests/ParserTest.php | 22 ---------------------- tests/fixtures/ie-hacks.css | 9 --------- 5 files changed, 2 insertions(+), 76 deletions(-) delete mode 100644 tests/fixtures/ie-hacks.css diff --git a/CHANGELOG.md b/CHANGELOG.md index 4bfcf0fa..ac243a9e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,7 @@ Please also have a look at our ### Removed +- Remove the IE hack in `Rule` (#995)) - Drop `getLineNo()` from the `Renderable` interface (#1038) - Remove `OutputFormat::level()` (#874) - Remove expansion of shorthand properties (#838) diff --git a/config/phpstan-baseline.neon b/config/phpstan-baseline.neon index f2969599..e17e1b3f 100644 --- a/config/phpstan-baseline.neon +++ b/config/phpstan-baseline.neon @@ -234,12 +234,6 @@ parameters: count: 1 path: ../src/Rule/Rule.php - - - message: '#^Construct empty\(\) is not allowed\. Use more strict comparison\.$#' - identifier: empty.notAllowed - count: 1 - path: ../src/Rule/Rule.php - - message: '#^Only booleans are allowed in an if condition, Sabberworm\\CSS\\Value\\RuleValueList\|string\|null given\.$#' identifier: if.condNotBoolean @@ -258,12 +252,6 @@ parameters: count: 1 path: ../src/Rule/Rule.php - - - message: '#^Parameters should have "string" types as the only types passed to this method$#' - identifier: typePerfect.narrowPublicClassMethodParamType - count: 1 - path: ../src/Rule/Rule.php - - message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:comments\(\)\.$#' identifier: method.notFound diff --git a/src/Rule/Rule.php b/src/Rule/Rule.php index 45cf24d0..997357f1 100644 --- a/src/Rule/Rule.php +++ b/src/Rule/Rule.php @@ -36,11 +36,6 @@ class Rule implements Renderable, Commentable */ private $isImportant = false; - /** - * @var array - */ - private $ieHack = []; - /** * @var int */ @@ -94,7 +89,7 @@ public static function parse(ParserState $parserState): Rule if ($parserState->getSettings()->usesLenientParsing()) { while ($parserState->comes('\\')) { $parserState->consume('\\'); - $rule->addIeHack($parserState->consume()); + $parserState->consume(); $parserState->consumeWhiteSpace(); } } @@ -220,30 +215,6 @@ public function addValue($value, $type = ' '): void } } - /** - * @param int $modifier - */ - public function addIeHack($modifier): void - { - $this->ieHack[] = $modifier; - } - - /** - * @param array $modifiers - */ - public function setIeHack(array $modifiers): void - { - $this->ieHack = $modifiers; - } - - /** - * @return array - */ - public function getIeHack() - { - return $this->ieHack; - } - /** * @param bool $isImportant */ @@ -276,9 +247,6 @@ public function render(OutputFormat $outputFormat): string } else { $result .= $this->value; } - if (!empty($this->ieHack)) { - $result .= ' \\' . \implode('\\', $this->ieHack); - } if ($this->isImportant) { $result .= ' !important'; } diff --git a/tests/ParserTest.php b/tests/ParserTest.php index 7a66f852..040011b7 100644 --- a/tests/ParserTest.php +++ b/tests/ParserTest.php @@ -1036,28 +1036,6 @@ public function unexpectedTokenExceptionLineNo(): void } } - /** - * @test - */ - public function ieHacksStrictParsing(): void - { - $this->expectException(UnexpectedTokenException::class); - - // We can't strictly parse IE hacks. - self::parsedStructureForFile('ie-hacks', Settings::create()->beStrict()); - } - - /** - * @test - */ - public function ieHacksParsing(): void - { - $document = self::parsedStructureForFile('ie-hacks', Settings::create()->withLenientParsing(true)); - $expected = 'p {padding-right: .75rem \\9;background-image: none \\9;color: red \\9\\0;' - . 'background-color: red \\9\\0;background-color: red \\9\\0 !important;content: "red \\0";content: "red઼";}'; - self::assertSame($expected, $document->render()); - } - /** * @depends files * diff --git a/tests/fixtures/ie-hacks.css b/tests/fixtures/ie-hacks.css deleted file mode 100644 index 3f5f215e..00000000 --- a/tests/fixtures/ie-hacks.css +++ /dev/null @@ -1,9 +0,0 @@ -p { - padding-right: .75rem \9; - background-image: none \9; - color:red\9\0; - background-color:red \9 \0; - background-color:red \9 \0 !important; - content: "red \9\0"; - content: "red\0abc"; -} From 1ef82445050b29eb3040f1ccf4756a1a306268ec Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Wed, 26 Feb 2025 09:18:58 +0100 Subject: [PATCH 2/3] Changes suggested in code review --- CHANGELOG.md | 2 +- src/Rule/Rule.php | 7 ------- tests/ParserTest.php | 22 ++++++++++++++++++++++ tests/fixtures/ie-hacks.css | 9 +++++++++ 4 files changed, 32 insertions(+), 8 deletions(-) create mode 100644 tests/fixtures/ie-hacks.css diff --git a/CHANGELOG.md b/CHANGELOG.md index ac243a9e..46fc107a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,7 +40,7 @@ Please also have a look at our ### Removed -- Remove the IE hack in `Rule` (#995)) +- Remove the IE hack in `Rule` (#995) - Drop `getLineNo()` from the `Renderable` interface (#1038) - Remove `OutputFormat::level()` (#874) - Remove expansion of shorthand properties (#838) diff --git a/src/Rule/Rule.php b/src/Rule/Rule.php index 997357f1..0ec26902 100644 --- a/src/Rule/Rule.php +++ b/src/Rule/Rule.php @@ -86,13 +86,6 @@ public static function parse(ParserState $parserState): Rule $parserState->consume(':'); $value = Value::parseValue($parserState, self::listDelimiterForRule($rule->getRule())); $rule->setValue($value); - if ($parserState->getSettings()->usesLenientParsing()) { - while ($parserState->comes('\\')) { - $parserState->consume('\\'); - $parserState->consume(); - $parserState->consumeWhiteSpace(); - } - } $parserState->consumeWhiteSpace(); if ($parserState->comes('!')) { $parserState->consume('!'); diff --git a/tests/ParserTest.php b/tests/ParserTest.php index 040011b7..2e432dfc 100644 --- a/tests/ParserTest.php +++ b/tests/ParserTest.php @@ -1036,6 +1036,28 @@ public function unexpectedTokenExceptionLineNo(): void } } + /** + * @test + */ + public function ieHacksCauseExceptionInStrictMode(): void + { + $this->expectException(UnexpectedTokenException::class); + + self::parsedStructureForFile('ie-hacks', Settings::create()->beStrict()); + } + + /** + * @test + */ + public function ieHacksArePartiallyRemovedInLenientMode(): void + { + $document = self::parsedStructureForFile('ie-hacks', Settings::create()->withLenientParsing(true)); + + $expected = 'p {padding-right: .75rem;background-image: none;color: red;' + . 'background-color: red;background-color: red;content: "red \\0";content: "red઼";}'; + self::assertSame($expected, $document->render()); + } + /** * @depends files * diff --git a/tests/fixtures/ie-hacks.css b/tests/fixtures/ie-hacks.css new file mode 100644 index 00000000..3f5f215e --- /dev/null +++ b/tests/fixtures/ie-hacks.css @@ -0,0 +1,9 @@ +p { + padding-right: .75rem \9; + background-image: none \9; + color:red\9\0; + background-color:red \9 \0; + background-color:red \9 \0 !important; + content: "red \9\0"; + content: "red\0abc"; +} From b0c8d8f592a3f197786a924e2ccf27032518a6ed Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Thu, 27 Feb 2025 10:05:15 +0100 Subject: [PATCH 3/3] Remove more ancient stuff --- src/Parsing/ParserState.php | 7 ------- src/Value/Value.php | 1 - tests/ParserTest.php | 22 ---------------------- tests/fixtures/ie-hacks.css | 9 --------- 4 files changed, 39 deletions(-) delete mode 100644 tests/fixtures/ie-hacks.css diff --git a/src/Parsing/ParserState.php b/src/Parsing/ParserState.php index b4885c17..2100ed35 100644 --- a/src/Parsing/ParserState.php +++ b/src/Parsing/ParserState.php @@ -150,13 +150,6 @@ public function parseIdentifier($ignoreCase = true) public function parseCharacter($isForIdentifier) { if ($this->peek() === '\\') { - if ( - $isForIdentifier && $this->parserSettings->usesLenientParsing() - && ($this->comes('\\0') || $this->comes('\\9')) - ) { - // Non-strings can contain \0 or \9 which is an IE hack supported in lenient parsing. - return null; - } $this->consume('\\'); if ($this->comes('\\n') || $this->comes('\\r')) { return ''; diff --git a/src/Value/Value.php b/src/Value/Value.php index dcd8686a..c14d74fa 100644 --- a/src/Value/Value.php +++ b/src/Value/Value.php @@ -50,7 +50,6 @@ public static function parseValue(ParserState $parserState, array $aListDelimite while ( !($parserState->comes('}') || $parserState->comes(';') || $parserState->comes('!') || $parserState->comes(')') - || $parserState->comes('\\') || $parserState->isEnd()) ) { if (\count($aStack) > 0) { diff --git a/tests/ParserTest.php b/tests/ParserTest.php index 2e432dfc..040011b7 100644 --- a/tests/ParserTest.php +++ b/tests/ParserTest.php @@ -1036,28 +1036,6 @@ public function unexpectedTokenExceptionLineNo(): void } } - /** - * @test - */ - public function ieHacksCauseExceptionInStrictMode(): void - { - $this->expectException(UnexpectedTokenException::class); - - self::parsedStructureForFile('ie-hacks', Settings::create()->beStrict()); - } - - /** - * @test - */ - public function ieHacksArePartiallyRemovedInLenientMode(): void - { - $document = self::parsedStructureForFile('ie-hacks', Settings::create()->withLenientParsing(true)); - - $expected = 'p {padding-right: .75rem;background-image: none;color: red;' - . 'background-color: red;background-color: red;content: "red \\0";content: "red઼";}'; - self::assertSame($expected, $document->render()); - } - /** * @depends files * diff --git a/tests/fixtures/ie-hacks.css b/tests/fixtures/ie-hacks.css deleted file mode 100644 index 3f5f215e..00000000 --- a/tests/fixtures/ie-hacks.css +++ /dev/null @@ -1,9 +0,0 @@ -p { - padding-right: .75rem \9; - background-image: none \9; - color:red\9\0; - background-color:red \9 \0; - background-color:red \9 \0 !important; - content: "red \9\0"; - content: "red\0abc"; -}