Skip to content

Commit

Permalink
Merge pull request #3 from sherbrow/fix-attr-bool2
Browse files Browse the repository at this point in the history
Validate Bool2 attribute with context attribute name
  • Loading branch information
xemlock authored Aug 14, 2017
2 parents 659582e + 8455fe5 commit 2317e94
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion library/HTMLPurifier/AttrDef/HTML/Bool2.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ class HTMLPurifier_AttrDef_HTML_Bool2 extends HTMLPurifier_AttrDef_HTML_Bool
*/
public function validate($string, $config, $context)
{
$name = $this->name ? : $context->get('CurrentAttr');
// boolean attribute validates if its value is either empty
// or case-insensitively equal to attribute name
return $string === '' || strcasecmp($this->name, $string) === 0;
return $string === '' || strcasecmp($name, $string) === 0;
}

/**
Expand Down
22 changes: 22 additions & 0 deletions tests/HTMLPurifier/HTML5DefinitionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,26 @@ public function testVideo($input)

$this->assertEquals($input, $output);
}

public function boolAttrInput()
{
return array(
array('<audio controls src="audio.ogg"></audio>', '<audio controls src="audio.ogg"></audio>'),
array('<audio controls="" src="audio.ogg"></audio>', '<audio controls src="audio.ogg"></audio>'),
array('<audio controls="controls" src="audio.ogg"></audio>', '<audio controls src="audio.ogg"></audio>'),
array('<audio controls="CoNtRoLs" src="audio.ogg"></audio>', '<audio controls src="audio.ogg"></audio>'),
array('<audio controls="bar" src="audio.ogg"></audio>', '<audio src="audio.ogg"></audio>'),
);
}

/**
* @dataProvider boolAttrInput
* @depends testAudio
*/
public function testBoolAttr($input, $expectedOuptut)
{
$output = $this->getPurifier()->purify($input);

$this->assertEquals($expectedOuptut, $output);
}
}

0 comments on commit 2317e94

Please sign in to comment.