diff --git a/README.md b/README.md index 74b4c27..da7ec4a 100755 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ Config file `config/purifier.php` should like this return [ 'encoding' => 'UTF-8', 'finalize' => true, - 'passThruNullValues' => false, + 'ignoreNonStrings' => false, 'cachePath' => storage_path('app/purifier'), 'cacheFileMode' => 0755, 'settings' => [ diff --git a/config/purifier.php b/config/purifier.php index 3974570..2afa4c3 100644 --- a/config/purifier.php +++ b/config/purifier.php @@ -19,7 +19,7 @@ return [ 'encoding' => 'UTF-8', 'finalize' => true, - 'passThruNullValues' => false, + 'ignoreNonStrings' => false, 'cachePath' => storage_path('app/purifier'), 'cacheFileMode' => 0755, 'settings' => [ diff --git a/src/Purifier.php b/src/Purifier.php index 68dae9f..9c06f02 100644 --- a/src/Purifier.php +++ b/src/Purifier.php @@ -273,13 +273,11 @@ public function clean($dirty, $config = null, \Closure $postCreateConfigHook = n } } - //If $dirty is explicit NULL, bypass purification assuming configuration allows this - $passThruNullValues = $this->config->get('purifier.passThruNullValues', false); - if($passThruNullValues !== false && $dirty === null) { - return null; - } - if($passThruNullValues !== false && $dirty === false) { - return false; + //If $dirty is not an explicit string, bypass purification assuming configuration allows this + $ignoreNonStrings = $this->config->get('purifier.ignoreNonStrings', false); + $stringTest = is_string($dirty); + if($stringTest === false && $ignoreNonStrings === true) { + return $dirty; } return $this->purifier->purify($dirty, $configObject); diff --git a/tests/PurifierTest.php b/tests/PurifierTest.php index d1b46cb..ad00018 100644 --- a/tests/PurifierTest.php +++ b/tests/PurifierTest.php @@ -119,7 +119,7 @@ public function testCleaningNullPassThru() { $purifier = new Purifier(new Filesystem(), $configRepo); //test default config value is expected - $this->assertEquals(false, $configRepo->get('purifier.passThruNullValues')); + $this->assertEquals(false, $configRepo->get('purifier.ignoreNonStrings')); //Test default behavior is unchanged without nullPassThru Config value of true $html = null; @@ -134,21 +134,25 @@ public function testCleaningNullPassThru() { 'bad'=>'', 'empty'=>null, 'bool'=>false, + 'bool2'=>true, + 'float'=>4.321, ]; $expectedHtml = [ 'good'=>'

This is my H1 title

', 'bad'=>'', 'empty'=>'', 'bool'=>'', + 'bool2'=>'

1

', + 'float'=>'

4.321

' ]; $pureHtml = $purifier->clean($html); $this->assertEquals($expectedHtml, $pureHtml); //Test behavior as expected with nullPassThru Config value of true - $configRepo->set('purifier.passThruNullValues', true); + $configRepo->set('purifier.ignoreNonStrings', true); $purifier = new Purifier(new Filesystem(), $configRepo); - $this->assertEquals(true, $configRepo->get('purifier.passThruNullValues')); + $this->assertEquals(true, $configRepo->get('purifier.ignoreNonStrings')); $html = null; $pureHtml = $purifier->clean($html); @@ -164,6 +168,8 @@ public function testCleaningNullPassThru() { 'empty'=>null, 'emptyStr'=>'', 'bool'=>false, + 'bool2'=>true, + 'float'=>4.321, ]; $expectedHtml = [ 'good'=>'

This is my H1 title

', @@ -171,6 +177,8 @@ public function testCleaningNullPassThru() { 'empty'=>null, 'emptyStr'=>'', 'bool'=>false, + 'bool2'=>true, + 'float'=>4.321, ]; $pureHtml = $purifier->clean($html); $this->assertEquals($expectedHtml, $pureHtml);