Skip to content

Commit

Permalink
Fix content category of <picture> (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
xemlock authored Jun 7, 2018
1 parent 99f3df7 commit b4b35e5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion library/HTMLPurifier/HTML5Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class HTMLPurifier_HTML5Config extends HTMLPurifier_Config
{
const REVISION = 2018060701;
const REVISION = 2018060702;

/**
* @param string|array|HTMLPurifier_Config $config
Expand Down
3 changes: 2 additions & 1 deletion library/HTMLPurifier/HTML5Definition.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ public static function setup(HTMLPurifier_HTMLDefinition $def)
));

// https://html.spec.whatwg.org/dev/embedded-content.html#the-picture-element
$def->addElement('picture', 'Block', new HTMLPurifier_ChildDef_Picture(), 'Common');
$def->addElement('picture', 'Flow', new HTMLPurifier_ChildDef_Picture(), 'Common');
$def->getAnonymousModule()->addElementToContentSet('picture', 'Inline');

// http://developers.whatwg.org/text-level-semantics.html
$def->addElement('s', 'Inline', 'Inline', 'Common');
Expand Down
11 changes: 9 additions & 2 deletions tests/HTMLPurifier/HTML5DefinitionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class HTMLPurifier_HTML5DefinitionTest extends PHPUnit_Framework_TestCase
public function getPurifier($config = null)
{
$config = HTMLPurifier_HTML5Config::create($config);
$config->set('Cache.DefinitionImpl', null);
$purifier = new HTMLPurifier($config);
return $purifier;
}
Expand Down Expand Up @@ -240,17 +241,23 @@ public function pictureInput()
'<picture><source src="image.webp" type="image/webp"></picture>',
'',
),
array(
// <picture> is a phrasing content element
'<span><picture><img src="image.png" alt=""></picture></span>',
),
);
}

/**
* @param string $input
* @param string $expectedOutput OPTIONAL
* @dataProvider pictureInput
*/
public function testPicture($input, $expectedOutput)
public function testPicture($input, $expectedOutput = null)
{
$output = $this->getPurifier()->purify($input);

$this->assertEquals($expectedOutput, $output);
$this->assertEquals($expectedOutput !== null ? $expectedOutput : $input, $output);
}

public function detailsInput()
Expand Down

0 comments on commit b4b35e5

Please sign in to comment.