Skip to content

Commit 1a184c1

Browse files
committed
Fix a element: allow flow content, add html5 attrs
1 parent 46bcdee commit 1a184c1

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

library/HTMLPurifier/HTML5Definition.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,15 @@ public static function setup(HTMLPurifier_HTMLDefinition $def)
8787
$time = $def->addElement('time', 'Inline', 'Inline', 'Common', array('datetime' => 'Text', 'pubdate' => 'Bool'));
8888
$time->excludes = array('time' => true);
8989

90+
// https://html.spec.whatwg.org/dev/text-level-semantics.html#the-a-element
91+
$def->addElement('a', 'Flow', 'Flow', 'Common', array(
92+
'download' => 'Text',
93+
'hreflang' => 'Text',
94+
'rel' => 'Text',
95+
'target' => new HTMLPurifier_AttrDef_HTML_FrameTarget(),
96+
'type' => 'Text',
97+
));
98+
9099
// IMG
91100
$def->addAttribute('img', 'srcset', 'Text');
92101

tests/HTMLPurifier/HTML5DefinitionTest.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,43 @@ public function testIframe()
3636
$this->assertEquals($input, $output);
3737
}
3838

39+
/**
40+
* Data provider for {@link testAnchor()}
41+
* @return array
42+
*/
43+
public function anchorInput()
44+
{
45+
return array(
46+
array(
47+
'<a href="foo" type="video/mp4" hreflang="en"><h1>Heading</h1><p>Description</p></a>',
48+
),
49+
array(
50+
'<a href="foo" target="_blank" rel="nofollow">Visit</a>',
51+
'<a href="foo" target="_blank" rel="nofollow noreferrer noopener">Visit</a>',
52+
),
53+
array(
54+
'<a href="foo" download>Download</a>',
55+
'<a href="foo" download="">Download</a>',
56+
),
57+
array(
58+
'<a href="foo" download="bar">Download</a>',
59+
),
60+
);
61+
}
62+
63+
/**
64+
* @param string $input
65+
* @param string $expectedOutput OPTIONAL
66+
* @dataProvider anchorInput
67+
*/
68+
public function testAnchor($input, $expectedOutput = null)
69+
{
70+
$output = $this->getPurifier(array(
71+
'Attr.AllowedFrameTargets' => array('_blank'),
72+
))->purify($input);
73+
$this->assertEquals($expectedOutput !== null ? $expectedOutput : $input, $output);
74+
}
75+
3976
public function figureInput()
4077
{
4178
return array(

0 commit comments

Comments
 (0)