mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-01-03 13:21:51 +00:00
[1.6.0] Add support for name transformation to id
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@921 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
parent
85374d330f
commit
1102dc6e27
1
NEWS
1
NEWS
@ -13,6 +13,7 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier
|
|||||||
! Support for all deprecated attributes via attribute transformations
|
! Support for all deprecated attributes via attribute transformations
|
||||||
+ bgcolor in td, th, tr and table
|
+ bgcolor in td, th, tr and table
|
||||||
+ border in img
|
+ border in img
|
||||||
|
+ name in a and img
|
||||||
+ (incomplete)
|
+ (incomplete)
|
||||||
|
|
||||||
1.5.1, unknown release date
|
1.5.1, unknown release date
|
||||||
|
@ -279,8 +279,8 @@ Mozilla on inside and needs -moz-outline, no IE support.</td></tr>
|
|||||||
<tr><td>height</td><td>TD, TH</td><td>Near-equiv style 'height', needs px suffix if original was in pixels</td></tr>
|
<tr><td>height</td><td>TD, TH</td><td>Near-equiv style 'height', needs px suffix if original was in pixels</td></tr>
|
||||||
<tr><td>hspace</td><td>IMG</td><td>Near-equiv styles 'margin-top' and 'margin-bottom', needs px suffix</td></tr>
|
<tr><td>hspace</td><td>IMG</td><td>Near-equiv styles 'margin-top' and 'margin-bottom', needs px suffix</td></tr>
|
||||||
<tr class="impl-yes"><td>lang</td><td>*</td><td>Copy value to xml:lang</td></tr>
|
<tr class="impl-yes"><td>lang</td><td>*</td><td>Copy value to xml:lang</td></tr>
|
||||||
<tr><td rowspan="2">name</td><td>IMG</td><td>Turn into ID</td></tr>
|
<tr class="impl-yes"><td rowspan="2">name</td><td>IMG</td><td>Turn into ID</td></tr>
|
||||||
<tr><td>A</td><td>Turn into ID? (not deprecated, though in which specs?)</td></tr>
|
<tr class="impl-yes"><td>A</td><td>Turn into ID</td></tr>
|
||||||
<tr><td>noshade</td><td>HR</td><td>Boolean, style 'border-style:solid;'</td></tr>
|
<tr><td>noshade</td><td>HR</td><td>Boolean, style 'border-style:solid;'</td></tr>
|
||||||
<tr><td>nowrap</td><td>TD, TH</td><td>Boolean, style 'white-space:nowrap;' (not compat with IE5)</td></tr>
|
<tr><td>nowrap</td><td>TD, TH</td><td>Boolean, style 'white-space:nowrap;' (not compat with IE5)</td></tr>
|
||||||
<tr><td>size</td><td>HR</td><td>Near-equiv 'width', needs px suffix if original was pixels</td></tr>
|
<tr><td>size</td><td>HR</td><td>Near-equiv 'width', needs px suffix if original was pixels</td></tr>
|
||||||
|
31
library/HTMLPurifier/AttrTransform/Name.php
Normal file
31
library/HTMLPurifier/AttrTransform/Name.php
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once 'HTMLPurifier/AttrTransform.php';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pre-transform that changes deprecated name attribute to ID if necessary
|
||||||
|
*/
|
||||||
|
class HTMLPurifier_AttrTransform_Name extends HTMLPurifier_AttrTransform
|
||||||
|
{
|
||||||
|
|
||||||
|
function transform($attr, $config, &$context) {
|
||||||
|
|
||||||
|
if (!isset($attr['name'])) return $attr;
|
||||||
|
|
||||||
|
$name = $attr['name'];
|
||||||
|
unset($attr['name']);
|
||||||
|
|
||||||
|
if (isset($attr['id'])) {
|
||||||
|
// ID already set, discard name
|
||||||
|
return $attr;
|
||||||
|
}
|
||||||
|
|
||||||
|
$attr['id'] = $name;
|
||||||
|
|
||||||
|
return $attr;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
@ -10,6 +10,7 @@ require_once 'HTMLPurifier/AttrTransform/Lang.php';
|
|||||||
require_once 'HTMLPurifier/AttrTransform/TextAlign.php';
|
require_once 'HTMLPurifier/AttrTransform/TextAlign.php';
|
||||||
require_once 'HTMLPurifier/AttrTransform/BgColor.php';
|
require_once 'HTMLPurifier/AttrTransform/BgColor.php';
|
||||||
require_once 'HTMLPurifier/AttrTransform/Border.php';
|
require_once 'HTMLPurifier/AttrTransform/Border.php';
|
||||||
|
require_once 'HTMLPurifier/AttrTransform/Name.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Proprietary module that transforms deprecated elements into Strict
|
* Proprietary module that transforms deprecated elements into Strict
|
||||||
@ -23,7 +24,7 @@ class HTMLPurifier_HTMLModule_TransformToStrict extends HTMLPurifier_HTMLModule
|
|||||||
|
|
||||||
// we're actually modifying these elements, not defining them
|
// we're actually modifying these elements, not defining them
|
||||||
var $elements = array('h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p',
|
var $elements = array('h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p',
|
||||||
'blockquote', 'table', 'td', 'th', 'tr', 'img');
|
'blockquote', 'table', 'td', 'th', 'tr', 'img', 'a');
|
||||||
|
|
||||||
var $info_tag_transform = array(
|
var $info_tag_transform = array(
|
||||||
// placeholders, see constructor for definitions
|
// placeholders, see constructor for definitions
|
||||||
@ -83,6 +84,9 @@ class HTMLPurifier_HTMLModule_TransformToStrict extends HTMLPurifier_HTMLModule
|
|||||||
|
|
||||||
$this->info['img']->attr_transform_pre['border'] = new HTMLPurifier_AttrTransform_Border();
|
$this->info['img']->attr_transform_pre['border'] = new HTMLPurifier_AttrTransform_Border();
|
||||||
|
|
||||||
|
$this->info['img']->attr_transform_pre['name'] =
|
||||||
|
$this->info['a']->attr_transform_pre['name'] = new HTMLPurifier_AttrTransform_Name();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var $defines_child_def = true;
|
var $defines_child_def = true;
|
||||||
|
28
tests/HTMLPurifier/AttrTransform/NameTest.php
Normal file
28
tests/HTMLPurifier/AttrTransform/NameTest.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once 'HTMLPurifier/AttrTransform/Name.php';
|
||||||
|
require_once 'HTMLPurifier/AttrTransformHarness.php';
|
||||||
|
|
||||||
|
class HTMLPurifier_AttrTransform_NameTest extends HTMLPurifier_AttrTransformHarness
|
||||||
|
{
|
||||||
|
|
||||||
|
function setUp() {
|
||||||
|
parent::setUp();
|
||||||
|
$this->obj = new HTMLPurifier_AttrTransform_Name();
|
||||||
|
}
|
||||||
|
|
||||||
|
function test() {
|
||||||
|
$this->assertResult( array() );
|
||||||
|
$this->assertResult(
|
||||||
|
array('name' => 'free'),
|
||||||
|
array('id' => 'free')
|
||||||
|
);
|
||||||
|
$this->assertResult(
|
||||||
|
array('name' => 'tryit', 'id' => 'tobad'),
|
||||||
|
array('id' => 'tobad')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
@ -172,6 +172,13 @@ class HTMLPurifier_Strategy_ValidateAttributesTest extends
|
|||||||
'<img src="" alt="Invalid image" />'
|
'<img src="" alt="Invalid image" />'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// name rewritten as id
|
||||||
|
$this->assertResult(
|
||||||
|
'<a name="foobar" />',
|
||||||
|
'<a id="foobar" />',
|
||||||
|
array('HTML.EnableAttrID' => true)
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,7 @@ $test_files[] = 'AttrTransform/BgColorTest.php';
|
|||||||
$test_files[] = 'AttrTransform/BorderTest.php';
|
$test_files[] = 'AttrTransform/BorderTest.php';
|
||||||
$test_files[] = 'AttrTransform/ImgRequiredTest.php';
|
$test_files[] = 'AttrTransform/ImgRequiredTest.php';
|
||||||
$test_files[] = 'AttrTransform/LangTest.php';
|
$test_files[] = 'AttrTransform/LangTest.php';
|
||||||
|
$test_files[] = 'AttrTransform/NameTest.php';
|
||||||
$test_files[] = 'AttrTransform/TextAlignTest.php';
|
$test_files[] = 'AttrTransform/TextAlignTest.php';
|
||||||
$test_files[] = 'ChildDef/ChameleonTest.php';
|
$test_files[] = 'ChildDef/ChameleonTest.php';
|
||||||
$test_files[] = 'ChildDef/CustomTest.php';
|
$test_files[] = 'ChildDef/CustomTest.php';
|
||||||
|
Loading…
Reference in New Issue
Block a user