Skip to content

Commit b4b35e5

Browse files
authored
Fix content category of <picture> (#19)
1 parent 99f3df7 commit b4b35e5

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

library/HTMLPurifier/HTML5Config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
class HTMLPurifier_HTML5Config extends HTMLPurifier_Config
44
{
5-
const REVISION = 2018060701;
5+
const REVISION = 2018060702;
66

77
/**
88
* @param string|array|HTMLPurifier_Config $config

library/HTMLPurifier/HTML5Definition.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ public static function setup(HTMLPurifier_HTMLDefinition $def)
7171
));
7272

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

7677
// http://developers.whatwg.org/text-level-semantics.html
7778
$def->addElement('s', 'Inline', 'Inline', 'Common');

tests/HTMLPurifier/HTML5DefinitionTest.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ class HTMLPurifier_HTML5DefinitionTest extends PHPUnit_Framework_TestCase
55
public function getPurifier($config = null)
66
{
77
$config = HTMLPurifier_HTML5Config::create($config);
8+
$config->set('Cache.DefinitionImpl', null);
89
$purifier = new HTMLPurifier($config);
910
return $purifier;
1011
}
@@ -240,17 +241,23 @@ public function pictureInput()
240241
'<picture><source src="image.webp" type="image/webp"></picture>',
241242
'',
242243
),
244+
array(
245+
// <picture> is a phrasing content element
246+
'<span><picture><img src="image.png" alt=""></picture></span>',
247+
),
243248
);
244249
}
245250

246251
/**
252+
* @param string $input
253+
* @param string $expectedOutput OPTIONAL
247254
* @dataProvider pictureInput
248255
*/
249-
public function testPicture($input, $expectedOutput)
256+
public function testPicture($input, $expectedOutput = null)
250257
{
251258
$output = $this->getPurifier()->purify($input);
252259

253-
$this->assertEquals($expectedOutput, $output);
260+
$this->assertEquals($expectedOutput !== null ? $expectedOutput : $input, $output);
254261
}
255262

256263
public function detailsInput()

0 commit comments

Comments
 (0)