Skip to content

Commit bbc2d73

Browse files
committed
[BUGFIX] Allow at-rules to be parsed in strict mode
The reverts the change to `CSSList` in 134f4e6 and adds a comment that `null` is an expected return value when the end of the list (or block) is reached. It also adds a convention, for now, that a test filename beginning with `=` should mean that it is initially tested with strict parsing enabled. Fixes #352
1 parent 52ff901 commit bbc2d73

File tree

5 files changed

+24
-11
lines changed

5 files changed

+24
-11
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ This project adheres to [Semantic Versioning](https://semver.org/).
1919

2020
### Fixed
2121

22+
Fix (regression) failure to parse at-rules with strict parsing (#456)
23+
2224
## 8.5.0
2325

2426
### Added

src/CSSList/CSSList.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -131,18 +131,15 @@ private static function parseListItem(ParserState $oParserState, CSSList $oList)
131131
}
132132
return $oAtRule;
133133
} elseif ($oParserState->comes('}')) {
134-
if (!$oParserState->getSettings()->bLenientParsing) {
135-
throw new UnexpectedTokenException('CSS selector', '}', 'identifier', $oParserState->currentLine());
136-
} else {
137-
if ($bIsRoot) {
138-
if ($oParserState->getSettings()->bLenientParsing) {
139-
return DeclarationBlock::parse($oParserState);
140-
} else {
141-
throw new SourceException("Unopened {", $oParserState->currentLine());
142-
}
134+
if ($bIsRoot) {
135+
if ($oParserState->getSettings()->bLenientParsing) {
136+
return DeclarationBlock::parse($oParserState);
143137
} else {
144-
return null;
138+
throw new SourceException("Unopened {", $oParserState->currentLine());
145139
}
140+
} else {
141+
// End of list
142+
return null;
146143
}
147144
} else {
148145
return DeclarationBlock::parse($oParserState, $oList);

tests/ParserTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@ public function files()
7474
// or a future test of a as-of-now missing feature
7575
continue;
7676
}
77-
$oParser = new Parser(file_get_contents($sDirectory . '/' . $sFileName));
77+
$oParser = new Parser(
78+
\file_get_contents($sDirectory . '/' . $sFileName),
79+
Settings::create()->withLenientParsing($sFileName[0] !== '=')
80+
);
7881
try {
7982
self::assertNotEquals('', $oParser->parse()->render());
8083
} catch (\Exception $e) {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@media (min-width: 1220px) {
2+
div { width:auto; }
3+
}

tests/fixtures/=at-media.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@media print
2+
{
3+
html
4+
{
5+
background: white;
6+
color: black;
7+
}
8+
}

0 commit comments

Comments
 (0)