PHP-CSS-Parser icon indicating copy to clipboard operation
PHP-CSS-Parser copied to clipboard

Strict parsing mode exception with whitespace-only CSS

Open JakeQZ opened this issue 2 years ago • 0 comments

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.

JakeQZ avatar Dec 20 '21 23:12 JakeQZ