From 72db5754467c9031dd9f7328b1248107bf8aa370 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Mon, 30 Jul 2012 10:54:32 -0400 Subject: [PATCH] Fix bug with non-lower case color names in HTML. Signed-off-by: Edward Z. Yang --- NEWS | 1 + library/HTMLPurifier/AttrDef/HTML/Color.php | 3 ++- tests/HTMLPurifier/AttrDef/HTML/ColorTest.php | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index f2de80ba..474e3df1 100644 --- a/NEWS +++ b/NEWS @@ -21,6 +21,7 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier - Fix bug with nofollow transform when pre-existing rel exists. - Fix bug where background:url() always gets lower-cased (but not background-image:url()) +- Fix bug with non lower-case color names in HTML 4.4.0, released 2012-01-18 # Removed PEARSax3 handler. diff --git a/library/HTMLPurifier/AttrDef/HTML/Color.php b/library/HTMLPurifier/AttrDef/HTML/Color.php index 00d86572..e02abb07 100644 --- a/library/HTMLPurifier/AttrDef/HTML/Color.php +++ b/library/HTMLPurifier/AttrDef/HTML/Color.php @@ -14,7 +14,8 @@ class HTMLPurifier_AttrDef_HTML_Color extends HTMLPurifier_AttrDef $string = trim($string); if (empty($string)) return false; - if (isset($colors[strtolower($string)])) return $colors[$string]; + $lower = strtolower($string); + if (isset($colors[$lower])) return $colors[$lower]; if ($string[0] === '#') $hex = substr($string, 1); else $hex = $string; diff --git a/tests/HTMLPurifier/AttrDef/HTML/ColorTest.php b/tests/HTMLPurifier/AttrDef/HTML/ColorTest.php index 8b4a4634..f2b21811 100644 --- a/tests/HTMLPurifier/AttrDef/HTML/ColorTest.php +++ b/tests/HTMLPurifier/AttrDef/HTML/ColorTest.php @@ -9,6 +9,7 @@ class HTMLPurifier_AttrDef_HTML_ColorTest extends HTMLPurifier_AttrDefHarness $this->assertDef('foo', false); $this->assertDef('43', false); $this->assertDef('red', '#FF0000'); + $this->assertDef('RED', '#FF0000'); $this->assertDef('#FF0000'); $this->assertDef('#453443'); $this->assertDef('453443', '#453443'); -- 2.11.4.GIT