mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-08-06 14:16:32 +02:00
[1.2.0] [BC] ID attributes now disabled by default. New directives:
+ %HTML.EnableAttrID - restores old behavior by allowing IDs + %Attr.IDPrefix - %Attr.IDBlacklist alternative that munges all user IDs so that they don't collide with your IDs + %Attr.IDPrefixLocal - Same as above, but for when there are multiple instances of user content on the page + Profuse documentation on how to use these available in id.txt git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@526 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
@@ -7,13 +7,17 @@ require_once 'HTMLPurifier/IDAccumulator.php';
|
||||
class HTMLPurifier_AttrDef_IDTest extends HTMLPurifier_AttrDefHarness
|
||||
{
|
||||
|
||||
function test() {
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->context = new HTMLPurifier_Context();
|
||||
$id_accumulator = new HTMLPurifier_IDAccumulator();
|
||||
$this->context->register('IDAccumulator', $id_accumulator);
|
||||
$this->def = new HTMLPurifier_AttrDef_ID();
|
||||
|
||||
}
|
||||
|
||||
function test() {
|
||||
|
||||
// valid ID names
|
||||
$this->assertDef('alpha');
|
||||
$this->assertDef('al_ha');
|
||||
@@ -34,6 +38,44 @@ class HTMLPurifier_AttrDef_IDTest extends HTMLPurifier_AttrDefHarness
|
||||
|
||||
}
|
||||
|
||||
function testPrefix() {
|
||||
|
||||
$this->config->set('Attr', 'IDPrefix', 'user_');
|
||||
|
||||
$this->assertDef('alpha', 'user_alpha');
|
||||
$this->assertDef('<asa', false);
|
||||
$this->assertDef('once', 'user_once');
|
||||
$this->assertDef('once', false);
|
||||
|
||||
// if already prefixed, leave alone
|
||||
$this->assertDef('user_alas');
|
||||
$this->assertDef('user_user_alas'); // how to bypass
|
||||
|
||||
}
|
||||
|
||||
function testTwoPrefixes() {
|
||||
|
||||
$this->config->set('Attr', 'IDPrefix', 'user_');
|
||||
$this->config->set('Attr', 'IDPrefixLocal', 'story95_');
|
||||
|
||||
$this->assertDef('alpha', 'user_story95_alpha');
|
||||
$this->assertDef('<asa', false);
|
||||
$this->assertDef('once', 'user_story95_once');
|
||||
$this->assertDef('once', false);
|
||||
|
||||
$this->assertDef('user_story95_alas');
|
||||
$this->assertDef('user_alas', 'user_story95_user_alas'); // !
|
||||
|
||||
$this->config->set('Attr', 'IDPrefix', '');
|
||||
$this->assertDef('amherst'); // no affect when IDPrefix isn't set
|
||||
$this->assertError('%Attr.IDPrefixLocal cannot be used unless '.
|
||||
'%Attr.IDPrefix is set');
|
||||
// SimpleTest has a bug and throws a sprintf error
|
||||
// $this->assertNoErrors();
|
||||
$this->swallowErrors();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@@ -21,17 +21,25 @@ class HTMLPurifier_Strategy_ValidateAttributesTest extends
|
||||
$this->assertResult('');
|
||||
|
||||
// test ids
|
||||
$this->assertResult('<div id="valid">Preserve the ID.</div>');
|
||||
$this->assertResult(
|
||||
'<div id="valid">Kill the ID.</div>',
|
||||
'<div>Kill the ID.</div>'
|
||||
);
|
||||
|
||||
$this->assertResult('<div id="valid">Preserve the ID.</div>', true,
|
||||
array('HTML.EnableAttrID' => true));
|
||||
|
||||
$this->assertResult(
|
||||
'<div id="0invalid">Kill the ID.</div>',
|
||||
'<div>Kill the ID.</div>'
|
||||
'<div>Kill the ID.</div>',
|
||||
array('HTML.EnableAttrID' => true)
|
||||
);
|
||||
|
||||
// test id accumulator
|
||||
$this->assertResult(
|
||||
'<div id="valid">Valid</div><div id="valid">Invalid</div>',
|
||||
'<div id="valid">Valid</div><div>Invalid</div>'
|
||||
'<div id="valid">Valid</div><div>Invalid</div>',
|
||||
array('HTML.EnableAttrID' => true)
|
||||
);
|
||||
|
||||
$this->assertResult(
|
||||
@@ -42,20 +50,25 @@ class HTMLPurifier_Strategy_ValidateAttributesTest extends
|
||||
// test attribute key case sensitivity
|
||||
$this->assertResult(
|
||||
'<div ID="valid">Convert ID to lowercase.</div>',
|
||||
'<div id="valid">Convert ID to lowercase.</div>'
|
||||
'<div id="valid">Convert ID to lowercase.</div>',
|
||||
array('HTML.EnableAttrID' => true)
|
||||
);
|
||||
|
||||
// test simple attribute substitution
|
||||
$this->assertResult(
|
||||
'<div id=" valid ">Trim whitespace.</div>',
|
||||
'<div id="valid">Trim whitespace.</div>'
|
||||
'<div id="valid">Trim whitespace.</div>',
|
||||
array('HTML.EnableAttrID' => true)
|
||||
);
|
||||
|
||||
// test configuration id blacklist
|
||||
$this->assertResult(
|
||||
'<div id="invalid">Invalid</div>',
|
||||
'<div>Invalid</div>',
|
||||
array('Attr.IDBlacklist' => array('invalid'))
|
||||
array(
|
||||
'Attr.IDBlacklist' => array('invalid'),
|
||||
'HTML.EnableAttrID' => true
|
||||
)
|
||||
);
|
||||
|
||||
// test classes
|
||||
|
Reference in New Issue
Block a user