Skip to content

Commit

Permalink
Add contenteditable attribute definition (#332)
Browse files Browse the repository at this point in the history
* Add contenteditable attribute definition

* gate behind html.trusted

* use enum
  • Loading branch information
bytestream authored Sep 6, 2022
1 parent 1c2bae1 commit dbbd3e5
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
16 changes: 16 additions & 0 deletions library/HTMLPurifier/AttrDef/HTML/ContentEditable.php
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);
}
}
1 change: 1 addition & 0 deletions library/HTMLPurifier/AttrTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function __construct()
$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();
Expand Down
27 changes: 27 additions & 0 deletions tests/HTMLPurifier/AttrDef/HTML/ContentEditableTest.php
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);
}
}

0 comments on commit dbbd3e5

Please sign in to comment.