Skip to content

Commit c468e71

Browse files
committed
Fix UnexpectedTokenException caused by trailing whitespace
1 parent 0c74522 commit c468e71

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

lib/Sabberworm/CSS/Parser.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ private function parseList(CSSList $oList, $bIsRoot = false) {
110110
$oListItem->setComments($comments);
111111
$oList->append($oListItem);
112112
}
113+
$this->consumeWhiteSpace();
113114
}
114115
if (!$bIsRoot) {
115116
throw new SourceException("Unexpected end of document", $this->iLineNo);
@@ -367,15 +368,18 @@ private function parseRule() {
367368
$this->consumeWhiteSpace();
368369
}
369370
}
371+
$this->consumeWhiteSpace();
370372
if ($this->comes('!')) {
371373
$this->consume('!');
372374
$this->consumeWhiteSpace();
373375
$this->consume('important');
374376
$oRule->setIsImportant(true);
375377
}
378+
$this->consumeWhiteSpace();
376379
while ($this->comes(';')) {
377380
$this->consume(';');
378381
}
382+
$this->consumeWhiteSpace();
379383
return $oRule;
380384
}
381385

tests/Sabberworm/CSS/ParserTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,12 @@ function testCharsetLenient2() {
432432
$this->assertSame($sExpected, $oDoc->render());
433433
}
434434

435+
function testTrailingWhitespace() {
436+
$oDoc = $this->parsedStructureForFile('trailing-whitespace', Settings::create()->withLenientParsing(false));
437+
$sExpected = 'div {width: 200px;}';
438+
$this->assertSame($sExpected, $oDoc->render());
439+
}
440+
435441
/**
436442
* @expectedException Sabberworm\CSS\Parsing\UnexpectedTokenException
437443
*/

tests/files/trailing-whitespace.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
div { width: 200px; }
2+

0 commit comments

Comments
 (0)