Skip to content
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 @@ -24,6 +24,7 @@ Please also have a look at our

### Fixed

- Improve recovery parsing when a rogue `}` is encountered (#1425)
- Parse comment(s) immediately preceding a selector (#1421)
- Parse consecutive comments (#1421)
- Support attribute selectors with values containing commas in
Expand Down
2 changes: 1 addition & 1 deletion src/RuleSet/DeclarationBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static function parse(ParserState $parserState, ?CSSList $list = null): ?
}
} catch (UnexpectedTokenException $e) {
if ($parserState->getSettings()->usesLenientParsing()) {
if (!$parserState->comes('}')) {
if (!$parserState->consumeIfComes('}')) {
$parserState->consumeUntil('}', false, true);
}
return null;
Expand Down
11 changes: 2 additions & 9 deletions tests/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,7 @@ public function invalidSelectorsInFile(): void
$document = self::parsedStructureForFile('invalid-selectors', Settings::create()->withMultibyteSupport(true));
$expected = '@keyframes mymove {from {top: 0px;}}
#test {color: white;background: green;}
#test {display: block;background: red;color: white;}
#test {display: block;background: white;color: black;}';
self::assertSame($expected, $document->render());

Expand All @@ -727,6 +728,7 @@ public function invalidSelectorsInFile(): void
.super-menu > li:last-of-type {border-right-width: 0;}
html[dir="rtl"] .super-menu > li:first-of-type {border-left-width: 1px;border-right-width: 0;}
html[dir="rtl"] .super-menu > li:last-of-type {border-left-width: 0;}}
.super-menu.menu-floated {border-right-width: 1px;border-left-width: 1px;border-color: #5a4242;border-style: dotted;}
body {background-color: red;}';
self::assertSame($expected, $document->render());
}
Expand All @@ -740,15 +742,6 @@ public function selectorEscapesInFile(): void
$expected = '#\\# {color: red;}
.col-sm-1\\/5 {width: 20%;}';
self::assertSame($expected, $document->render());

$document = self::parsedStructureForFile('invalid-selectors-2', Settings::create()->withMultibyteSupport(true));
$expected = '@media only screen and (max-width: 1215px) {.breadcrumb {padding-left: 10px;}
.super-menu > li:first-of-type {border-left-width: 0;}
.super-menu > li:last-of-type {border-right-width: 0;}
html[dir="rtl"] .super-menu > li:first-of-type {border-left-width: 1px;border-right-width: 0;}
html[dir="rtl"] .super-menu > li:last-of-type {border-left-width: 0;}}
body {background-color: red;}';
self::assertSame($expected, $document->render());
}

/**
Expand Down
39 changes: 39 additions & 0 deletions tests/Unit/RuleSet/DeclarationBlockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,45 @@ public function parseSkipsBlockWithInvalidSelector(string $selector): void
self::assertTrue($parserState->comes($nextCss));
}

/**
* @return array<non-empty-string, array{0: non-empty-string}>
*/
public static function provideClosingBrace(): array
{
return [
'as is' => ['}'],
'with space before' => [' }'],
'with newline before' => ["\n}"],
];
}

/**
* @return DataProvider<non-empty-string, array{0: non-empty-string, 1: non-empty-string}>
*/
public static function provideInvalidSelectorAndClosingBrace(): DataProvider
{
return DataProvider::cross(self::provideInvalidSelector(), self::provideClosingBrace());
}

/**
* TODO: It's probably not the responsibility of `DeclarationBlock` to deal with this.
*
* @test
*
* @param non-empty-string $selector
* @param non-empty-string $closingBrace
*
* @dataProvider provideInvalidSelectorAndClosingBrace
*/
public function parseConsumesClosingBraceAfterInvalidSelector(string $selector, string $closingBrace): void
{
$parserState = new ParserState($selector . $closingBrace, Settings::create());

DeclarationBlock::parse($parserState);

self::assertTrue($parserState->isEnd());
}

/**
* @return array<string>
*/
Expand Down