Skip to content

Strict parsing mode exception with whitespace-only CSS #349

Description

@JakeQZ

In the following test, only the empty string passes:

    public function provideEmptyCss()
    {
        return [
            'empty string' => [''],
            'space' => [' '],
            'newline' => ["\n"],
            'carriage return' => ["\r"],
            'tab' => ["\t"],
            'Windows line ending' => ["\r\n"],
            'comment' => ['/**/'],
        ];
    }

    /**
     * @test
     *
     * @dataProvider provideEmptyCss
     */
    public function parsesEmptyCssInStrictMode($css)
    {
        $oParser = new Parser($css, Settings::create()->beStrict());

        self::assertSame('', $oParser->parse()->render());
    }

The others fail:

Sabberworm\CSS\Parsing\UnexpectedEOFException: Next token was expected to have 1 chars. Context: “”. [line no: 1]

D:\Data\dev\PHP-CSS-Parser\src\Parsing\ParserState.php:279
D:\Data\dev\PHP-CSS-Parser\src\RuleSet\DeclarationBlock.php:58
D:\Data\dev\PHP-CSS-Parser\src\CSSList\CSSList.php:146
D:\Data\dev\PHP-CSS-Parser\src\CSSList\CSSList.php:82
D:\Data\dev\PHP-CSS-Parser\src\CSSList\Document.php:35
D:\Data\dev\PHP-CSS-Parser\src\Parser.php:58
D:\Data\dev\PHP-CSS-Parser\tests\ParserTest.php:90

The lenient-mode equivalent test passes fine, however.

Metadata

Metadata

Assignees

Labels

Type

Fields

No fields configured for Bug.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions