From 23d3490d49cdd72e39a65406de06168a7114b58a Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Sun, 14 Jan 2007 16:24:02 +0000 Subject: [PATCH] [1.4.0] Implemented list-style-image, URIs now allowed in list-style git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@640 48356398-32a2-884e-a903-53898d9a118a --- NEWS | 1 + library/HTMLPurifier/AttrDef/ListStyle.php | 14 ++++++++++++-- library/HTMLPurifier/CSSDefinition.php | 2 ++ tests/HTMLPurifier/AttrDef/CSSTest.php | 3 +++ 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index 3365bc70..2356f0fa 100644 --- a/NEWS +++ b/NEWS @@ -10,6 +10,7 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier ========================== 1.4.0, unknown release date +! Implemented list-style-image, URIs now allowed in list-style . Implemented AttrDef_CSSURI for url(http://google.com) style declarations 1.3.3, unknown release date, likely to be dropped diff --git a/library/HTMLPurifier/AttrDef/ListStyle.php b/library/HTMLPurifier/AttrDef/ListStyle.php index a2df527a..a4ea815a 100644 --- a/library/HTMLPurifier/AttrDef/ListStyle.php +++ b/library/HTMLPurifier/AttrDef/ListStyle.php @@ -20,6 +20,7 @@ class HTMLPurifier_AttrDef_ListStyle extends HTMLPurifier_AttrDef $def = $config->getCSSDefinition(); $this->info['list-style-type'] = $def->info['list-style-type']; $this->info['list-style-position'] = $def->info['list-style-position']; + $this->info['list-style-image'] = $def->info['list-style-image']; } function validate($string, $config, &$context) { @@ -32,13 +33,14 @@ class HTMLPurifier_AttrDef_ListStyle extends HTMLPurifier_AttrDef $caught_type = false; $caught_position = false; + $caught_image = false; $caught_none = false; // as in keyword none, which is in all of them $ret = ''; foreach ($bits as $bit) { - if ($caught_none && ($caught_type || $caught_position)) break; - if ($caught_type && $caught_position) break; + if ($caught_none && ($caught_type || $caught_position || $caught_image)) break; + if ($caught_type && $caught_position && $caught_image) break; if ($bit === '') continue; @@ -66,6 +68,14 @@ class HTMLPurifier_AttrDef_ListStyle extends HTMLPurifier_AttrDef $ret .= $r . ' '; continue; } + + $r = $this->info['list-style-image']->validate($bit, $config, $context); + if ($r !== false) { + if ($caught_image) continue; + $caught_image = true; + $ret .= $r . ' '; + continue; + } } $ret = rtrim($ret); diff --git a/library/HTMLPurifier/CSSDefinition.php b/library/HTMLPurifier/CSSDefinition.php index 5647c4b7..ac646939 100644 --- a/library/HTMLPurifier/CSSDefinition.php +++ b/library/HTMLPurifier/CSSDefinition.php @@ -11,6 +11,7 @@ require_once 'HTMLPurifier/AttrDef/FontFamily.php'; require_once 'HTMLPurifier/AttrDef/Font.php'; require_once 'HTMLPurifier/AttrDef/Border.php'; require_once 'HTMLPurifier/AttrDef/ListStyle.php'; +require_once 'HTMLPurifier/AttrDef/CSSURI.php'; /** * Defines allowed CSS attributes and what their values are. @@ -56,6 +57,7 @@ class HTMLPurifier_CSSDefinition $this->info['list-style-type'] = new HTMLPurifier_AttrDef_Enum( array('disc', 'circle', 'square', 'decimal', 'lower-roman', 'upper-roman', 'lower-alpha', 'upper-alpha'), false); + $this->info['list-style-image'] = new HTMLPurifier_AttrDef_CSSURI(); $this->info['list-style'] = new HTMLPurifier_AttrDef_ListStyle($config); diff --git a/tests/HTMLPurifier/AttrDef/CSSTest.php b/tests/HTMLPurifier/AttrDef/CSSTest.php index 7afa2172..336914e2 100644 --- a/tests/HTMLPurifier/AttrDef/CSSTest.php +++ b/tests/HTMLPurifier/AttrDef/CSSTest.php @@ -1,6 +1,7 @@ assertDef('vertical-align:12px;'); $this->assertDef('vertical-align:50%;'); $this->assertDef('table-layout:fixed;'); + $this->assertDef('list-style-image:url(nice.jpg);'); + $this->assertDef('list-style:inside url(nice.jpg) disc;'); // duplicates $this->assertDef('text-align:right;text-align:left;',