Skip to content

Commit

Permalink
Correctly parse negative numbers with no leading 0
Browse files Browse the repository at this point in the history
closes #54 as fixed
  • Loading branch information
sabberworm committed Mar 19, 2013
1 parent 6322db9 commit a80739f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/Sabberworm/CSS/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ private static function listDelimiterForRule($sRule) {
private function parsePrimitiveValue() {
$oValue = null;
$this->consumeWhiteSpace();
if (is_numeric($this->peek()) || (($this->comes('-') || $this->comes('.')) && is_numeric($this->peek(1, 1)))) {
if (is_numeric($this->peek()) || ($this->comes('-.') && is_numeric($this->peek(1, 2))) || (($this->comes('-') || $this->comes('.')) && is_numeric($this->peek(1, 1)))) {
$oValue = $this->parseNumericValue();
} else if ($this->comes('#') || $this->comes('rgb') || $this->comes('hsl')) {
$oValue = $this->parseColorValue();
Expand Down
6 changes: 3 additions & 3 deletions tests/Sabberworm/CSS/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ function testSpecificity() {

function testManipulation() {
$oDoc = $this->parsedStructureForFile('atrules');
$this->assertSame('@charset "utf-8";@font-face {font-family: "CrassRoots";src: url("../media/cr.ttf");}html, body {font-size: 1.6em;}
$this->assertSame('@charset "utf-8";@font-face {font-family: "CrassRoots";src: url("../media/cr.ttf");}html, body {font-size: -0.6em;}
@keyframes mymove {from {top: 0px;}
to {top: 200px;}
}@-moz-keyframes some-move {from {top: 0px;}
Expand All @@ -167,7 +167,7 @@ function testManipulation() {
$oSelector->setSelector('#my_id ' . $oSelector->getSelector());
}
}
$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;}
$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;}
@keyframes mymove {from {top: 0px;}
to {top: 200px;}
}@-moz-keyframes some-move {from {top: 0px;}
Expand Down Expand Up @@ -316,7 +316,7 @@ function testListValueRemoval() {
continue;
}
}
$this->assertSame('html, body {font-size: 1.6em;}' . "\n", $oDoc->__toString());
$this->assertSame('html, body {font-size: -0.6em;}' . "\n", $oDoc->__toString());

$oDoc = $this->parsedStructureForFile('nested');
foreach ($oDoc->getAllDeclarationBlocks() as $oBlock) {
Expand Down
2 changes: 1 addition & 1 deletion tests/files/atrules.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
}

html, body {
font-size: 1.6em
font-size: -0.6em
}

@keyframes mymove {
Expand Down

0 comments on commit a80739f

Please sign in to comment.