Skip to content

Commit 68a3452

Browse files
authored
Merge pull request MyIntervals#134 from raxbg/trailing_whitespace_fix
Fix UnexpectedTokenException caused by trailing whitespace
2 parents 52e9057 + c468e71 commit 68a3452

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
@@ -111,6 +111,7 @@ private function parseList(CSSList $oList, $bIsRoot = false) {
111111
$oListItem->setComments($comments);
112112
$oList->append($oListItem);
113113
}
114+
$this->consumeWhiteSpace();
114115
}
115116
if (!$bIsRoot) {
116117
throw new SourceException("Unexpected end of document", $this->iLineNo);
@@ -368,15 +369,18 @@ private function parseRule() {
368369
$this->consumeWhiteSpace();
369370
}
370371
}
372+
$this->consumeWhiteSpace();
371373
if ($this->comes('!')) {
372374
$this->consume('!');
373375
$this->consumeWhiteSpace();
374376
$this->consume('important');
375377
$oRule->setIsImportant(true);
376378
}
379+
$this->consumeWhiteSpace();
377380
while ($this->comes(';')) {
378381
$this->consume(';');
379382
}
383+
$this->consumeWhiteSpace();
380384
return $oRule;
381385
}
382386

tests/Sabberworm/CSS/ParserTest.php

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

454+
function testTrailingWhitespace() {
455+
$oDoc = $this->parsedStructureForFile('trailing-whitespace', Settings::create()->withLenientParsing(false));
456+
$sExpected = 'div {width: 200px;}';
457+
$this->assertSame($sExpected, $oDoc->render());
458+
}
459+
454460
/**
455461
* @expectedException Sabberworm\CSS\Parsing\UnexpectedTokenException
456462
*/

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)