Skip to content

Commit a80739f

Browse files
committed
Correctly parse negative numbers with no leading 0
closes MyIntervals#54 as fixed
1 parent 6322db9 commit a80739f

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

lib/Sabberworm/CSS/Parser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ private static function listDelimiterForRule($sRule) {
357357
private function parsePrimitiveValue() {
358358
$oValue = null;
359359
$this->consumeWhiteSpace();
360-
if (is_numeric($this->peek()) || (($this->comes('-') || $this->comes('.')) && is_numeric($this->peek(1, 1)))) {
360+
if (is_numeric($this->peek()) || ($this->comes('-.') && is_numeric($this->peek(1, 2))) || (($this->comes('-') || $this->comes('.')) && is_numeric($this->peek(1, 1)))) {
361361
$oValue = $this->parseNumericValue();
362362
} else if ($this->comes('#') || $this->comes('rgb') || $this->comes('hsl')) {
363363
$oValue = $this->parseColorValue();

tests/Sabberworm/CSS/ParserTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ function testSpecificity() {
149149

150150
function testManipulation() {
151151
$oDoc = $this->parsedStructureForFile('atrules');
152-
$this->assertSame('@charset "utf-8";@font-face {font-family: "CrassRoots";src: url("../media/cr.ttf");}html, body {font-size: 1.6em;}
152+
$this->assertSame('@charset "utf-8";@font-face {font-family: "CrassRoots";src: url("../media/cr.ttf");}html, body {font-size: -0.6em;}
153153
@keyframes mymove {from {top: 0px;}
154154
to {top: 200px;}
155155
}@-moz-keyframes some-move {from {top: 0px;}
@@ -167,7 +167,7 @@ function testManipulation() {
167167
$oSelector->setSelector('#my_id ' . $oSelector->getSelector());
168168
}
169169
}
170-
$this->assertSame('@charset "utf-8";@font-face {font-family: "CrassRoots";src: url("../media/cr.ttf");}#my_id html, #my_id body {font-size: 1.6em;}
170+
$this->assertSame('@charset "utf-8";@font-face {font-family: "CrassRoots";src: url("../media/cr.ttf");}#my_id html, #my_id body {font-size: -0.6em;}
171171
@keyframes mymove {from {top: 0px;}
172172
to {top: 200px;}
173173
}@-moz-keyframes some-move {from {top: 0px;}
@@ -316,7 +316,7 @@ function testListValueRemoval() {
316316
continue;
317317
}
318318
}
319-
$this->assertSame('html, body {font-size: 1.6em;}' . "\n", $oDoc->__toString());
319+
$this->assertSame('html, body {font-size: -0.6em;}' . "\n", $oDoc->__toString());
320320

321321
$oDoc = $this->parsedStructureForFile('nested');
322322
foreach ($oDoc->getAllDeclarationBlocks() as $oBlock) {

tests/files/atrules.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
}
77

88
html, body {
9-
font-size: 1.6em
9+
font-size: -0.6em
1010
}
1111

1212
@keyframes mymove {

0 commit comments

Comments
 (0)