diff --git a/lib/Sabberworm/CSS/Parser.php b/lib/Sabberworm/CSS/Parser.php index 42392b9c..b87c07f5 100644 --- a/lib/Sabberworm/CSS/Parser.php +++ b/lib/Sabberworm/CSS/Parser.php @@ -43,16 +43,6 @@ public function __construct($sText, Settings $oParserSettings = null) { } $this->oParserSettings = $oParserSettings; $this->blockRules = explode('/', AtRule::BLOCK_RULES); - - foreach (explode('/', Size::ABSOLUTE_SIZE_UNITS.'/'.Size::RELATIVE_SIZE_UNITS.'/'.Size::NON_SIZE_UNITS) as $val) { - $size = strlen($val); - if (isset($this->sizeUnits[$size])) { - $this->sizeUnits[$size][] = $val; - } else { - $this->sizeUnits[$size] = array($val); - } - } - ksort($this->sizeUnits, SORT_NUMERIC); } public function setCharset($sCharset) { @@ -66,6 +56,19 @@ public function getCharset() { public function parse() { $this->setCharset($this->oParserSettings->sDefaultCharset); + + $this->sizeUnits = array(); + foreach (explode('/', Size::ABSOLUTE_SIZE_UNITS.'/'.Size::RELATIVE_SIZE_UNITS.'/'.Size::NON_SIZE_UNITS) as $val) { + $val = $this->strtolower($val); + $size = strlen($val); + if (isset($this->sizeUnits[$size])) { + $this->sizeUnits[$size][] = $val; + } else { + $this->sizeUnits[$size] = array($val); + } + } + ksort($this->sizeUnits, SORT_NUMERIC); + $oResult = new Document(); $this->parseDocument($oResult); return $oResult; @@ -409,8 +412,9 @@ private function parseNumericValue($bForColor = false) { $sUnit = null; foreach ($this->sizeUnits as $len => $val) { - if (($pos = array_search($this->peek($len), $val)) !== false) { - $sUnit = $val[$pos]; + $peek = $this->peek($len); + if (array_search($this->strtolower($peek), $val) !== false) { + $sUnit = $peek; $this->consume($len); break; } diff --git a/tests/Sabberworm/CSS/RuleSet/LenientParsingTest.php b/tests/Sabberworm/CSS/RuleSet/LenientParsingTest.php index f2ddebd1..cf4eccda 100644 --- a/tests/Sabberworm/CSS/RuleSet/LenientParsingTest.php +++ b/tests/Sabberworm/CSS/RuleSet/LenientParsingTest.php @@ -44,7 +44,7 @@ public function testCaseInsensitivity() { $sFile = dirname(__FILE__) . '/../../../files' . DIRECTORY_SEPARATOR . "case-insensitivity.css"; $oParser = new Parser(file_get_contents($sFile)); $oResult = $oParser->parse(); - $this->assertSame('@charset "utf-8";@import url("test.css");@media screen {}#myid {case: insensitive !important;frequency: 30Hz;color: #ff0;color: hsl(40,40%,30%);font-family: Arial;}'."\n", $oResult->__toString()); + $this->assertSame('@charset "utf-8";@import url("test.css");@media screen {}#myid {case: insensitive !important;frequency: 30hz;color: #ff0;color: hsl(40,40%,30%);font-family: Arial;}'."\n", $oResult->__toString()); } }