From d4da02ba957ab6312ec347edf39bba14da967536 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Thu, 15 May 2008 04:26:30 +0000 Subject: [PATCH] [2.1.4] [MFH] Case-insensitive CSS from r1461 git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/branches/php4@1712 48356398-32a2-884e-a903-53898d9a118a --- NEWS | 1 + library/HTMLPurifier/AttrDef/CSS.php | 15 ++++++++++++++- tests/HTMLPurifier/AttrDef/CSSTest.php | 3 +++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 11b3936a..88793641 100644 --- a/NEWS +++ b/NEWS @@ -11,6 +11,7 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier 2.1.4, unknown release date ! DefinitionCacheFactory now can register new implementations +! CSS properties are now case-insensitive - Colors missing # but in hex form will be corrected - CSS Number algorithm improved diff --git a/library/HTMLPurifier/AttrDef/CSS.php b/library/HTMLPurifier/AttrDef/CSS.php index d0f49bc4..71523be1 100644 --- a/library/HTMLPurifier/AttrDef/CSS.php +++ b/library/HTMLPurifier/AttrDef/CSS.php @@ -38,7 +38,20 @@ class HTMLPurifier_AttrDef_CSS extends HTMLPurifier_AttrDef list($property, $value) = explode(':', $declaration, 2); $property = trim($property); $value = trim($value); - if (!isset($definition->info[$property])) continue; + $ok = false; + do { + if (isset($definition->info[$property])) { + $ok = true; + break; + } + if (ctype_lower($property)) break; + $property = strtolower($property); + if (isset($definition->info[$property])) { + $ok = true; + break; + } + } while(0); + if (!$ok) continue; // inefficient call, since the validator will do this again if (strtolower(trim($value)) !== 'inherit') { // inherit works for everything (but only on the base property) diff --git a/tests/HTMLPurifier/AttrDef/CSSTest.php b/tests/HTMLPurifier/AttrDef/CSSTest.php index 994fad12..59d86e2e 100644 --- a/tests/HTMLPurifier/AttrDef/CSSTest.php +++ b/tests/HTMLPurifier/AttrDef/CSSTest.php @@ -107,6 +107,9 @@ class HTMLPurifier_AttrDef_CSSTest extends HTMLPurifier_AttrDefHarness $this->assertDef(' font-weight : bold; color : #ff0000', 'font-weight:bold;color:#ff0000;'); + // case-insensitivity + $this->assertDef('FLOAT:LEFT;', 'float:left;'); + } }