Skip to content

Commit 2317e94

Browse files
authored
Merge pull request #3 from sherbrow/fix-attr-bool2
Validate Bool2 attribute with context attribute name
2 parents 659582e + 8455fe5 commit 2317e94

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

library/HTMLPurifier/AttrDef/HTML/Bool2.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ class HTMLPurifier_AttrDef_HTML_Bool2 extends HTMLPurifier_AttrDef_HTML_Bool
1919
*/
2020
public function validate($string, $config, $context)
2121
{
22+
$name = $this->name ? : $context->get('CurrentAttr');
2223
// boolean attribute validates if its value is either empty
2324
// or case-insensitively equal to attribute name
24-
return $string === '' || strcasecmp($this->name, $string) === 0;
25+
return $string === '' || strcasecmp($name, $string) === 0;
2526
}
2627

2728
/**

tests/HTMLPurifier/HTML5DefinitionTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,26 @@ public function testVideo($input)
9595

9696
$this->assertEquals($input, $output);
9797
}
98+
99+
public function boolAttrInput()
100+
{
101+
return array(
102+
array('<audio controls src="audio.ogg"></audio>', '<audio controls src="audio.ogg"></audio>'),
103+
array('<audio controls="" src="audio.ogg"></audio>', '<audio controls src="audio.ogg"></audio>'),
104+
array('<audio controls="controls" src="audio.ogg"></audio>', '<audio controls src="audio.ogg"></audio>'),
105+
array('<audio controls="CoNtRoLs" src="audio.ogg"></audio>', '<audio controls src="audio.ogg"></audio>'),
106+
array('<audio controls="bar" src="audio.ogg"></audio>', '<audio src="audio.ogg"></audio>'),
107+
);
108+
}
109+
110+
/**
111+
* @dataProvider boolAttrInput
112+
* @depends testAudio
113+
*/
114+
public function testBoolAttr($input, $expectedOuptut)
115+
{
116+
$output = $this->getPurifier()->purify($input);
117+
118+
$this->assertEquals($expectedOuptut, $output);
119+
}
98120
}

0 commit comments

Comments
 (0)