@@ -111,6 +111,79 @@ public function testCleaningWithCustomConfigAndPostCreateHook()
111111 $ this ->assertSame ('<p><a href="https://example.com">https://example.com</a></p> ' , $ pureHtml );
112112 }
113113
114+ public function testCleaningNullPassThru () {
115+ $ testConfig = require __DIR__ .'/../config/purifier.php ' ;
116+ $ configRepo = new Repository (['purifier ' =>$ testConfig ]);
117+
118+ //$purifier = $this->app->make('purifier');
119+ $ purifier = new Purifier (new Filesystem (), $ configRepo );
120+
121+ //test default config value is expected
122+ $ this ->assertEquals (false , $ configRepo ->get ('purifier.ignoreNonStrings ' ));
123+
124+ //Test default behavior is unchanged without nullPassThru Config value of true
125+ $ html = null ;
126+ $ pureHtml = $ purifier ->clean ($ html );
127+ $ this ->assertEquals ('' , $ pureHtml );
128+ $ html = false ;
129+ $ pureHtml = $ purifier ->clean ($ html );
130+ $ this ->assertEquals ('' , $ pureHtml );
131+
132+ $ html = [
133+ 'good ' =>'<span id="some-id">This is my H1 title ' ,
134+ 'bad ' =>'<script>alert( \'XSS \');</script> ' ,
135+ 'empty ' =>null ,
136+ 'bool ' =>false ,
137+ 'bool2 ' =>true ,
138+ 'float ' =>4.321 ,
139+ ];
140+ $ expectedHtml = [
141+ 'good ' =>'<p><span>This is my H1 title</span></p> ' ,
142+ 'bad ' =>'' ,
143+ 'empty ' =>'' ,
144+ 'bool ' =>'' ,
145+ 'bool2 ' =>'<p>1</p> ' ,
146+ 'float ' =>'<p>4.321</p> '
147+ ];
148+ $ pureHtml = $ purifier ->clean ($ html );
149+ $ this ->assertEquals ($ expectedHtml , $ pureHtml );
150+
151+
152+ //Test behavior as expected with nullPassThru Config value of true
153+ $ configRepo ->set ('purifier.ignoreNonStrings ' , true );
154+ $ purifier = new Purifier (new Filesystem (), $ configRepo );
155+ $ this ->assertEquals (true , $ configRepo ->get ('purifier.ignoreNonStrings ' ));
156+
157+ $ html = null ;
158+ $ pureHtml = $ purifier ->clean ($ html );
159+ $ this ->assertEquals (null , $ pureHtml );
160+
161+ $ html = false ;
162+ $ pureHtml = $ purifier ->clean ($ html );
163+ $ this ->assertEquals (false , $ pureHtml );
164+
165+ $ html = [
166+ 'good ' =>'<span id="some-id">This is my H1 title ' ,
167+ 'bad ' =>'<script>alert( \'XSS \');</script> ' ,
168+ 'empty ' =>null ,
169+ 'emptyStr ' =>'' ,
170+ 'bool ' =>false ,
171+ 'bool2 ' =>true ,
172+ 'float ' =>4.321 ,
173+ ];
174+ $ expectedHtml = [
175+ 'good ' =>'<p><span>This is my H1 title</span></p> ' ,
176+ 'bad ' =>'' ,
177+ 'empty ' =>null ,
178+ 'emptyStr ' =>'' ,
179+ 'bool ' =>false ,
180+ 'bool2 ' =>true ,
181+ 'float ' =>4.321 ,
182+ ];
183+ $ pureHtml = $ purifier ->clean ($ html );
184+ $ this ->assertEquals ($ expectedHtml , $ pureHtml );
185+ }
186+
114187 public function testCustomDefinitions ()
115188 {
116189 /** @var HTMLPurifier $purifier */
0 commit comments