Skip to content

Commit

Permalink
Also allow explicit boolean FALSE through
Browse files Browse the repository at this point in the history
  • Loading branch information
incentify-dev committed Mar 22, 2021
1 parent bc12b36 commit cf47484
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/Purifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,9 @@ public function clean($dirty, $config = null, \Closure $postCreateConfigHook = n
if($passThruNullValues !== false && $dirty === null) {
return null;
}
if($passThruNullValues !== false && $dirty === false) {
return false;
}

return $this->purifier->purify($dirty, $configObject);
}
Expand Down
13 changes: 12 additions & 1 deletion tests/PurifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,21 @@ public function testCleaningNullPassThru() {
$html = null;
$pureHtml = $purifier->clean($html);
$this->assertEquals('', $pureHtml);
$html = false;
$pureHtml = $purifier->clean($html);
$this->assertEquals('', $pureHtml);

$html = [
'good'=>'<span id="some-id">This is my H1 title',
'bad'=>'<script>alert(\'XSS\');</script>',
'empty'=>null,
'bool'=>false,
];
$expectedHtml = [
'good'=>'<p><span>This is my H1 title</span></p>',
'bad'=>'',
'empty'=>'',
'bool'=>'',
];
$pureHtml = $purifier->clean($html);
$this->assertEquals($expectedHtml, $pureHtml);
Expand All @@ -147,19 +152,25 @@ public function testCleaningNullPassThru() {

$html = null;
$pureHtml = $purifier->clean($html);
$this->assertEquals('', $pureHtml);
$this->assertEquals(null, $pureHtml);

$html = false;
$pureHtml = $purifier->clean($html);
$this->assertEquals(false, $pureHtml);

$html = [
'good'=>'<span id="some-id">This is my H1 title',
'bad'=>'<script>alert(\'XSS\');</script>',
'empty'=>null,
'emptyStr'=>'',
'bool'=>false,
];
$expectedHtml = [
'good'=>'<p><span>This is my H1 title</span></p>',
'bad'=>'',
'empty'=>null,
'emptyStr'=>'',
'bool'=>false,
];
$pureHtml = $purifier->clean($html);
$this->assertEquals($expectedHtml, $pureHtml);
Expand Down

0 comments on commit cf47484

Please sign in to comment.