mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2024-11-09 15:28:40 +00:00
Add contenteditable attribute definition (#332)
* Add contenteditable attribute definition * gate behind html.trusted * use enum
This commit is contained in:
parent
1c2bae18e3
commit
dbbd3e59f9
16
library/HTMLPurifier/AttrDef/HTML/ContentEditable.php
Normal file
16
library/HTMLPurifier/AttrDef/HTML/ContentEditable.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_AttrDef_HTML_ContentEditable extends HTMLPurifier_AttrDef
|
||||
{
|
||||
public function validate($string, $config, $context)
|
||||
{
|
||||
$allowed = array('false');
|
||||
if ($config->get('HTML.Trusted')) {
|
||||
$allowed = array('', 'true', 'false');
|
||||
}
|
||||
|
||||
$enum = new HTMLPurifier_AttrDef_Enum($allowed);
|
||||
|
||||
return $enum->validate($string, $config, $context);
|
||||
}
|
||||
}
|
@ -41,6 +41,7 @@ class HTMLPurifier_AttrTypes
|
||||
$this->info['IAlign'] = self::makeEnum('top,middle,bottom,left,right');
|
||||
$this->info['LAlign'] = self::makeEnum('top,bottom,left,right');
|
||||
$this->info['FrameTarget'] = new HTMLPurifier_AttrDef_HTML_FrameTarget();
|
||||
$this->info['ContentEditable'] = new HTMLPurifier_AttrDef_HTML_ContentEditable();
|
||||
|
||||
// unimplemented aliases
|
||||
$this->info['ContentType'] = new HTMLPurifier_AttrDef_Text();
|
||||
|
27
tests/HTMLPurifier/AttrDef/HTML/ContentEditableTest.php
Normal file
27
tests/HTMLPurifier/AttrDef/HTML/ContentEditableTest.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
class HTMLPurifier_AttrDef_HTML_ContentEditableTest extends HTMLPurifier_AttrDefHarness
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->def = new HTMLPurifier_AttrDef_HTML_ContentEditable();
|
||||
}
|
||||
|
||||
public function test()
|
||||
{
|
||||
$this->assertDef('', false);
|
||||
$this->assertDef('true', false);
|
||||
$this->assertDef('caret', false);
|
||||
$this->assertDef('false');
|
||||
}
|
||||
|
||||
public function testTrustedHtml()
|
||||
{
|
||||
$this->config->set('HTML.Trusted', true);
|
||||
$this->assertDef('');
|
||||
$this->assertDef('true');
|
||||
$this->assertDef('false');
|
||||
$this->assertDef('caret', false);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user