From 06ea34b9df2e19fc675e57e4645a4e799bf51264 Mon Sep 17 00:00:00 2001 From: Jan Schneider Date: Fri, 19 Jul 2013 12:06:29 +0200 Subject: [PATCH 1/5] Only replace 0. with . at the begin of a size value. --- lib/Sabberworm/CSS/Value/Size.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Sabberworm/CSS/Value/Size.php b/lib/Sabberworm/CSS/Value/Size.php index 05cf78c3..587a7589 100644 --- a/lib/Sabberworm/CSS/Value/Size.php +++ b/lib/Sabberworm/CSS/Value/Size.php @@ -61,7 +61,7 @@ public function isRelative() { public function __toString() { $l = localeconv(); - return str_replace(array($l['decimal_point'], '0.'), '.', $this->fSize) . ($this->sUnit === null ? '' : $this->sUnit); + return preg_replace(array('/' . $l['decimal_point'] . '/', '/^0./'), '.', $this->fSize) . ($this->sUnit === null ? '' : $this->sUnit); } } From 96d7218f8e51dc16722cd7b56b036ac14f2f016f Mon Sep 17 00:00:00 2001 From: Jan Schneider Date: Fri, 19 Jul 2013 16:09:30 +0200 Subject: [PATCH 2/5] Escape special characters. --- lib/Sabberworm/CSS/Value/Size.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Sabberworm/CSS/Value/Size.php b/lib/Sabberworm/CSS/Value/Size.php index 587a7589..03b13ae2 100644 --- a/lib/Sabberworm/CSS/Value/Size.php +++ b/lib/Sabberworm/CSS/Value/Size.php @@ -61,7 +61,7 @@ public function isRelative() { public function __toString() { $l = localeconv(); - return preg_replace(array('/' . $l['decimal_point'] . '/', '/^0./'), '.', $this->fSize) . ($this->sUnit === null ? '' : $this->sUnit); + return preg_replace(array('/' . preg_quote($l['decimal_point'], '/') . '/', '/^0\./'), '.', $this->fSize) . ($this->sUnit === null ? '' : $this->sUnit); } } From 3519d930fa13943d5df60d1bca2700614fc2b8b2 Mon Sep 17 00:00:00 2001 From: Jan Schneider Date: Fri, 19 Jul 2013 16:14:43 +0200 Subject: [PATCH 3/5] Fix incorrect unit tests. These should have catched the bug fixed in PR #65. Now they do. --- tests/Sabberworm/CSS/RuleSet/LenientParsingTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Sabberworm/CSS/RuleSet/LenientParsingTest.php b/tests/Sabberworm/CSS/RuleSet/LenientParsingTest.php index a2d2b2fe..f2ddebd1 100644 --- a/tests/Sabberworm/CSS/RuleSet/LenientParsingTest.php +++ b/tests/Sabberworm/CSS/RuleSet/LenientParsingTest.php @@ -20,7 +20,7 @@ public function testFaultToleranceOn() { $sFile = dirname(__FILE__) . '/../../../files' . DIRECTORY_SEPARATOR . "-fault-tolerance.css"; $oParser = new Parser(file_get_contents($sFile), Settings::create()->withLenientParsing(true)); $oResult = $oParser->parse(); - $this->assertSame('.test1 {}'."\n".'.test2 {hello: 2.2;hello: 200000000000.2;}'."\n".'#test {}'."\n".'#test2 {help: none;}'."\n", $oResult->__toString()); + $this->assertSame('.test1 {}'."\n".'.test2 {hello: 2.2;hello: 2000000000000.2;}'."\n".'#test {}'."\n".'#test2 {help: none;}'."\n", $oResult->__toString()); } /** @@ -37,7 +37,7 @@ public function testLocaleTrap() { $sFile = dirname(__FILE__) . '/../../../files' . DIRECTORY_SEPARATOR . "-fault-tolerance.css"; $oParser = new Parser(file_get_contents($sFile), Settings::create()->withLenientParsing(true)); $oResult = $oParser->parse(); - $this->assertSame('.test1 {}'."\n".'.test2 {hello: 2.2;hello: 200000000000.2;}'."\n".'#test {}'."\n".'#test2 {help: none;}'."\n", $oResult->__toString()); + $this->assertSame('.test1 {}'."\n".'.test2 {hello: 2.2;hello: 2000000000000.2;}'."\n".'#test {}'."\n".'#test2 {help: none;}'."\n", $oResult->__toString()); } public function testCaseInsensitivity() { From a8bd3a6514828357f40474322c1b995e11e6a8f0 Mon Sep 17 00:00:00 2001 From: Jan Schneider Date: Fri, 19 Jul 2013 16:16:44 +0200 Subject: [PATCH 4/5] Catch negative values too. --- lib/Sabberworm/CSS/Value/Size.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Sabberworm/CSS/Value/Size.php b/lib/Sabberworm/CSS/Value/Size.php index 03b13ae2..84628bf4 100644 --- a/lib/Sabberworm/CSS/Value/Size.php +++ b/lib/Sabberworm/CSS/Value/Size.php @@ -61,7 +61,7 @@ public function isRelative() { public function __toString() { $l = localeconv(); - return preg_replace(array('/' . preg_quote($l['decimal_point'], '/') . '/', '/^0\./'), '.', $this->fSize) . ($this->sUnit === null ? '' : $this->sUnit); + return preg_replace(array('/' . preg_quote($l['decimal_point'], '/') . '/', '/^(-?)0\./'), '$1.', $this->fSize) . ($this->sUnit === null ? '' : $this->sUnit); } } From 8ca038a639205c655a4958798370d6fb70efa543 Mon Sep 17 00:00:00 2001 From: Jan Schneider Date: Fri, 19 Jul 2013 16:18:59 +0200 Subject: [PATCH 5/5] Add PHPUnit configuration to load bootstrap.php. --- tests/phpunit.xml | 1 + 1 file changed, 1 insertion(+) create mode 100644 tests/phpunit.xml diff --git a/tests/phpunit.xml b/tests/phpunit.xml new file mode 100644 index 00000000..5dcbab2b --- /dev/null +++ b/tests/phpunit.xml @@ -0,0 +1 @@ +