diff --git a/lib/Sabberworm/CSS/Parser.php b/lib/Sabberworm/CSS/Parser.php index aeed48ef..51fe6944 100644 --- a/lib/Sabberworm/CSS/Parser.php +++ b/lib/Sabberworm/CSS/Parser.php @@ -110,6 +110,7 @@ private function parseList(CSSList $oList, $bIsRoot = false) { $oListItem->setComments($comments); $oList->append($oListItem); } + $this->consumeWhiteSpace(); } if (!$bIsRoot) { throw new SourceException("Unexpected end of document", $this->iLineNo); @@ -367,15 +368,18 @@ private function parseRule() { $this->consumeWhiteSpace(); } } + $this->consumeWhiteSpace(); if ($this->comes('!')) { $this->consume('!'); $this->consumeWhiteSpace(); $this->consume('important'); $oRule->setIsImportant(true); } + $this->consumeWhiteSpace(); while ($this->comes(';')) { $this->consume(';'); } + $this->consumeWhiteSpace(); return $oRule; } diff --git a/tests/Sabberworm/CSS/ParserTest.php b/tests/Sabberworm/CSS/ParserTest.php index 0cc3fe96..97105457 100644 --- a/tests/Sabberworm/CSS/ParserTest.php +++ b/tests/Sabberworm/CSS/ParserTest.php @@ -432,6 +432,12 @@ function testCharsetLenient2() { $this->assertSame($sExpected, $oDoc->render()); } + function testTrailingWhitespace() { + $oDoc = $this->parsedStructureForFile('trailing-whitespace', Settings::create()->withLenientParsing(false)); + $sExpected = 'div {width: 200px;}'; + $this->assertSame($sExpected, $oDoc->render()); + } + /** * @expectedException Sabberworm\CSS\Parsing\UnexpectedTokenException */ diff --git a/tests/files/trailing-whitespace.css b/tests/files/trailing-whitespace.css new file mode 100644 index 00000000..159e50c7 --- /dev/null +++ b/tests/files/trailing-whitespace.css @@ -0,0 +1,2 @@ +div { width: 200px; } +