Skip to content

[TASK] Remove the IE hack in Rule #995

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

Merged
merged 3 commits into from
Mar 2, 2025
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 @@ -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)
Expand Down
12 changes: 0 additions & 12 deletions config/phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
7 changes: 0 additions & 7 deletions src/Parsing/ParserState.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 '';
Expand Down
39 changes: 0 additions & 39 deletions src/Rule/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ class Rule implements Renderable, Commentable
*/
private $isImportant = false;

/**
* @var array<int, int>
*/
private $ieHack = [];

/**
* @var int
*/
Expand Down Expand Up @@ -91,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('\\');
$rule->addIeHack($parserState->consume());
$parserState->consumeWhiteSpace();
}
}
$parserState->consumeWhiteSpace();
if ($parserState->comes('!')) {
$parserState->consume('!');
Expand Down Expand Up @@ -220,30 +208,6 @@ public function addValue($value, $type = ' '): void
}
}

/**
* @param int $modifier
*/
public function addIeHack($modifier): void
{
$this->ieHack[] = $modifier;
}

/**
* @param array<int, int> $modifiers
*/
public function setIeHack(array $modifiers): void
{
$this->ieHack = $modifiers;
}

/**
* @return array<int, int>
*/
public function getIeHack()
{
return $this->ieHack;
}

/**
* @param bool $isImportant
*/
Expand Down Expand Up @@ -276,9 +240,6 @@ public function render(OutputFormat $outputFormat): string
} else {
$result .= $this->value;
}
if (!empty($this->ieHack)) {
$result .= ' \\' . \implode('\\', $this->ieHack);
}
if ($this->isImportant) {
$result .= ' !important';
}
Expand Down
1 change: 0 additions & 1 deletion src/Value/Value.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
22 changes: 0 additions & 22 deletions tests/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
9 changes: 0 additions & 9 deletions tests/fixtures/ie-hacks.css

This file was deleted.