diff --git a/NEWS b/NEWS index 21746f6e..cbb47927 100644 --- a/NEWS +++ b/NEWS @@ -18,6 +18,8 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier + height in td, th + (incomplete) ! Support for CSS attribute 'height' added +! Support for rel and rev attributes in a tags added, use %Attr.AllowedRel + and %Attr.AllowedRev to activate 1.5.1, unknown release date - Fix segfault in unit test. The problem is not very reproduceable and diff --git a/library/HTMLPurifier/AttrDef/HTML/LinkTypes.php b/library/HTMLPurifier/AttrDef/HTML/LinkTypes.php new file mode 100644 index 00000000..45c17cb2 --- /dev/null +++ b/library/HTMLPurifier/AttrDef/HTML/LinkTypes.php @@ -0,0 +1,74 @@ + 'AllowedRel', + 'rev' => 'AllowedRev' + ); + + /** Name config attribute to pull. */ + var $name; + + function HTMLPurifier_AttrDef_HTML_LinkTypes($name) { + if (!isset($this->configLookup[$name])) { + trigger_error('Unrecognized attribute name for link '. + 'relationship.', E_USER_ERROR); + return; + } + $this->name = $this->configLookup[$name]; + } + + function validate($string, $config, &$context) { + + $allowed = $config->get('Attr', $this->name); + if (empty($allowed)) return false; + + $string = $this->parseCDATA($string); + $parts = explode(' ', $string); + + // lookup to prevent duplicates + $ret_lookup = array(); + foreach ($parts as $part) { + $part = strtolower(trim($part)); + if (!isset($allowed[$part])) continue; + $ret_lookup[$part] = true; + } + + if (empty($ret_lookup)) return false; + + $ret_array = array(); + foreach ($ret_lookup as $part => $bool) $ret_array[] = $part; + $string = implode(' ', $ret_array); + + return $string; + + } + +} + +?> \ No newline at end of file diff --git a/library/HTMLPurifier/HTMLModule/Hypertext.php b/library/HTMLPurifier/HTMLModule/Hypertext.php index 0b8a2e98..e285e8ba 100644 --- a/library/HTMLPurifier/HTMLModule/Hypertext.php +++ b/library/HTMLPurifier/HTMLModule/Hypertext.php @@ -1,6 +1,7 @@ 'Charset', 'href' => 'URI', //'hreflang' => 'LanguageCode', - //'rel' => 'LinkTypes', - //'rev' => 'LinkTypes', + 'rel' => new HTMLPurifier_AttrDef_HTML_LinkTypes('rel'), + 'rev' => new HTMLPurifier_AttrDef_HTML_LinkTypes('rev'), //'tabindex' => 'Number', //'type' => 'ContentType', ); diff --git a/tests/HTMLPurifier/AttrDef/HTML/LinkTypesTest.php b/tests/HTMLPurifier/AttrDef/HTML/LinkTypesTest.php new file mode 100644 index 00000000..0acfac03 --- /dev/null +++ b/tests/HTMLPurifier/AttrDef/HTML/LinkTypesTest.php @@ -0,0 +1,24 @@ +def = new HTMLPurifier_AttrDef_HTML_LinkTypes('rel'); + $this->config->set('Attr', 'AllowedRel', array('nofollow', 'foo')); + + $this->assertDef('', false); + $this->assertDef('nofollow', true); + $this->assertDef('nofollow foo', true); + $this->assertDef('nofollow bar', 'nofollow'); + $this->assertDef('bar', false); + + } + +} + +?> \ No newline at end of file diff --git a/tests/HTMLPurifier/Strategy/ValidateAttributesTest.php b/tests/HTMLPurifier/Strategy/ValidateAttributesTest.php index 76614f8c..7d800bab 100644 --- a/tests/HTMLPurifier/Strategy/ValidateAttributesTest.php +++ b/tests/HTMLPurifier/Strategy/ValidateAttributesTest.php @@ -185,6 +185,13 @@ class HTMLPurifier_Strategy_ValidateAttributesTest extends '
' ); + // link types + $this->assertResult( + '', + true, + array('Attr.AllowedRel' => 'nofollow') + ); + } } diff --git a/tests/test_files.php b/tests/test_files.php index 2b870dca..c2fc532a 100644 --- a/tests/test_files.php +++ b/tests/test_files.php @@ -24,6 +24,7 @@ $test_files[] = 'AttrDef/HTML/LengthTest.php'; $test_files[] = 'AttrDef/HTML/MultiLengthTest.php'; $test_files[] = 'AttrDef/HTML/NmtokensTest.php'; $test_files[] = 'AttrDef/HTML/PixelsTest.php'; +$test_files[] = 'AttrDef/HTML/LinkTypesTest.php'; $test_files[] = 'AttrDef/IntegerTest.php'; $test_files[] = 'AttrDef/LangTest.php'; $test_files[] = 'AttrDef/TextTest.php';