Skip to content

Commit

Permalink
Make HTML5Config::inherit() return an instance of HTML5Config. Fixes #16
Browse files Browse the repository at this point in the history
  • Loading branch information
xemlock committed Jun 7, 2018
1 parent f41db89 commit 6f44fa7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
11 changes: 11 additions & 0 deletions library/HTMLPurifier/HTML5Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ public static function createDefault()
return $config;
}

/**
* Creates a new config object that inherits from a previous one
*
* @param HTMLPurifier_Config $config
* @return HTMLPurifier_Config
*/
public static function inherit(HTMLPurifier_Config $config)
{
return new self($config->def, $config->plist);
}

public function getDefinition($type, $raw = false, $optimized = false)
{
// Setting HTML.* keys removes any previously instantiated HTML
Expand Down
15 changes: 15 additions & 0 deletions tests/HTMLPurifier/HTML5ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,19 @@ public function testCreate()
$this->assertInstanceOf('HTMLPurifier_Config', $config4);
$this->assertEquals('iso-8859-1', $config4->get('Core.Encoding'));
}

public function testInherit()
{
$parent = HTMLPurifier_Config::create(array(
'Core.Encoding' => 'iso-8859-2',
'HTML.Trusted' => true,
));

$config = HTMLPurifier_HTML5Config::inherit($parent);

$this->assertInstanceof('HTMLPurifier_Config', $config);
$this->assertSame($parent->def, $config->def);
$this->assertEquals('iso-8859-2', $config->get('Core.Encoding'));
$this->assertTrue($config->get('HTML.Trusted'));
}
}

0 comments on commit 6f44fa7

Please sign in to comment.