-
Notifications
You must be signed in to change notification settings - Fork 338
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add contenteditable attribute definition (#332)
* Add contenteditable attribute definition * gate behind html.trusted * use enum
- Loading branch information
1 parent
1c2bae1
commit dbbd3e5
Showing
3 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |