From fbf0724da4ce21266cdbc033e39b2e8bdbd74921 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Tue, 19 Mar 2013 23:39:06 -0600 Subject: [PATCH 1/2] Better way of expressing multiple units Also will make it easier to extend this check --- lib/Sabberworm/CSS/Parser.php | 36 ++++++++++++----------------------- 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/lib/Sabberworm/CSS/Parser.php b/lib/Sabberworm/CSS/Parser.php index ccbba6ae..59cd623c 100644 --- a/lib/Sabberworm/CSS/Parser.php +++ b/lib/Sabberworm/CSS/Parser.php @@ -385,32 +385,20 @@ private function parseNumericValue($bForColor = false) { } } $fSize = floatval($sSize); + $sUnit = null; - if ($this->comes('%')) { - $sUnit = $this->consume('%'); - } else if ($this->comes('em')) { - $sUnit = $this->consume('em'); - } else if ($this->comes('ex')) { - $sUnit = $this->consume('ex'); - } else if ($this->comes('px')) { - $sUnit = $this->consume('px'); - } else if ($this->comes('deg')) { - $sUnit = $this->consume('deg'); - } else if ($this->comes('s')) { - $sUnit = $this->consume('s'); - } else if ($this->comes('cm')) { - $sUnit = $this->consume('cm'); - } else if ($this->comes('pt')) { - $sUnit = $this->consume('pt'); - } else if ($this->comes('in')) { - $sUnit = $this->consume('in'); - } else if ($this->comes('pc')) { - $sUnit = $this->consume('pc'); - } else if ($this->comes('cm')) { - $sUnit = $this->consume('cm'); - } else if ($this->comes('mm')) { - $sUnit = $this->consume('mm'); + $units = array( + '%', 'em', 'ex', 'px', 'deg', 's', 'cm', 'pt', 'in', 'pc', 'cm', + 'mm' + ); + + foreach ($units as $val) { + if ($this->comes($val)) { + $sUnit = $this->consume($val); + break; + } } + return new Size($fSize, $sUnit, $bForColor); } From 607e65b6e89bae89f2a7d352c499e3c2fe2324e6 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Tue, 19 Mar 2013 23:40:46 -0600 Subject: [PATCH 2/2] Fix bug preventing non 'size' numeric values from being parsed correctly e.g. 10ms was being parsed as Size:10 String:ms, not Size:10ms --- lib/Sabberworm/CSS/Parser.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/Sabberworm/CSS/Parser.php b/lib/Sabberworm/CSS/Parser.php index 59cd623c..f3d05331 100644 --- a/lib/Sabberworm/CSS/Parser.php +++ b/lib/Sabberworm/CSS/Parser.php @@ -389,7 +389,9 @@ private function parseNumericValue($bForColor = false) { $sUnit = null; $units = array( '%', 'em', 'ex', 'px', 'deg', 's', 'cm', 'pt', 'in', 'pc', 'cm', - 'mm' + 'mm', + // These are non "size" values, but they are still numeric + 'deg', 'grad', 'rad', 'turns', 's', 'ms', 'Hz', 'kHz' ); foreach ($units as $val) {