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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Please also have a look at our

### Fixed

- Improve recovery parsing when a rogue `}` is encountered (#1425)
- Improve recovery parsing when a rogue `}` is encountered (#1425, #1426)
- Parse comment(s) immediately preceding a selector (#1421)
- Parse consecutive comments (#1421)
- Support attribute selectors with values containing commas in
Expand Down
3 changes: 2 additions & 1 deletion src/CSSList/CSSList.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ private static function parseListItem(ParserState $parserState, CSSList $list)
} elseif ($parserState->comes('}')) {
if ($isRoot) {
if ($parserState->getSettings()->usesLenientParsing()) {
return DeclarationBlock::parse($parserState) ?? false;
$parserState->consume(1);
return self::parseListItem($parserState, $list);
} else {
throw new SourceException('Unopened {', $parserState->currentLine());
}
Expand Down
38 changes: 38 additions & 0 deletions tests/Unit/CSSList/CSSListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@
use PHPUnit\Framework\TestCase;
use Sabberworm\CSS\Comment\Commentable;
use Sabberworm\CSS\CSSElement;
use Sabberworm\CSS\CSSList\CSSList;
use Sabberworm\CSS\CSSList\CSSListItem;
use Sabberworm\CSS\CSSList\Document;
use Sabberworm\CSS\OutputFormat;
use Sabberworm\CSS\Parsing\ParserState;
use Sabberworm\CSS\Property\Selector;
use Sabberworm\CSS\Renderable;
use Sabberworm\CSS\RuleSet\DeclarationBlock;
use Sabberworm\CSS\Settings;
use Sabberworm\CSS\Tests\Unit\CSSList\Fixtures\ConcreteCSSList;

/**
Expand Down Expand Up @@ -342,4 +347,37 @@ public function removeDeclarationBlockBySelectorRemovesMultipleBlocksWithStringS

self::assertSame([], $subject->getContents());
}

/**
* The content provided must (currently) be in the same format as the expected rendering.
*
* @return array<non-empty-string, array{0: non-empty-string}>
*/
public function provideValidContentForParsing(): array
{
return [
'at-import rule' => ['@import url("foo.css");'],
'rule with declaration block' => ['a {color: green;}'],
];
}

/**
* @test
*
* @param non-empty-string $followingContent
*
* @dataProvider provideValidContentForParsing
*/
public function parseListAtRootLevelSkipsErroneousClosingBraceAndParsesFollowingContent(
string $followingContent
): void {
$parserState = new ParserState('}' . $followingContent, Settings::create());
// The subject needs to be a `Document`, as that is currently the test for 'root level'.
// Otherwise `}` will be treated as 'end of list'.
$subject = new Document();

CSSList::parseList($parserState, $subject);

self::assertSame($followingContent, $subject->render(new OutputFormat()));
}
}