Skip to content

Commit e94cb16

Browse files
authored
[TASK] Consume to EOF in DeclarationBlock::parse() upon failure (#1431)
This is not the right long-term fix - see #1430. For now it is a sticking-plaster to help complete #1424.
1 parent 539c64c commit e94cb16

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

src/RuleSet/DeclarationBlock.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public static function parse(ParserState $parserState, ?CSSList $list = null): ?
7575
} catch (UnexpectedTokenException $e) {
7676
if ($parserState->getSettings()->usesLenientParsing()) {
7777
if (!$parserState->consumeIfComes('}')) {
78-
$parserState->consumeUntil('}', false, true);
78+
$parserState->consumeUntil(['}', ParserState::EOF], false, true);
7979
}
8080
return null;
8181
} else {

tests/Unit/RuleSet/DeclarationBlockTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,46 @@ public function parseConsumesClosingBraceAfterInvalidSelector(string $selector,
231231
self::assertTrue($parserState->isEnd());
232232
}
233233

234+
/**
235+
* @return array<non-empty-string, array{0: string}>
236+
*/
237+
public static function provideOptionalWhitespace(): array
238+
{
239+
return [
240+
'none' => [''],
241+
'space' => [' '],
242+
'newline' => ["\n"],
243+
];
244+
}
245+
246+
/**
247+
* @return DataProvider<non-empty-string, array{0: non-empty-string, 1: string}>
248+
*/
249+
public static function provideInvalidSelectorAndOptionalWhitespace(): DataProvider
250+
{
251+
return DataProvider::cross(self::provideInvalidSelector(), self::provideOptionalWhitespace());
252+
}
253+
254+
/**
255+
* TODO: It's probably not the responsibility of `DeclarationBlock` to deal with this.
256+
*
257+
* @test
258+
*
259+
* @param non-empty-string $selector
260+
*
261+
* @dataProvider provideInvalidSelectorAndOptionalWhitespace
262+
*/
263+
public function parseConsumesToEofIfNoClosingBraceAfterInvalidSelector(
264+
string $selector,
265+
string $optionalWhitespace
266+
): void {
267+
$parserState = new ParserState($selector . $optionalWhitespace, Settings::create());
268+
269+
DeclarationBlock::parse($parserState);
270+
271+
self::assertTrue($parserState->isEnd());
272+
}
273+
234274
/**
235275
* @return array<string>
236276
*/

0 commit comments

Comments
 (0)