Posted on 2008-10-17 05:41:52-07 by djrbourg
Failing tests --ok?
I'm getting an install error which seems to occur almost universally looking at the test reports on cpan:
t/03security..... # Failed test 'HTML/XML entities' # at t/03security.t line 35. # got: '<p>unsafe</p>' # expected: '<p>unsafe</p>&lt;script' # Failed test 'HTML/XML entities with incomplete tag' # at t/03security.t line 40. # got: '' # expected: '&lt;p attr_ok=&quot;test&gt;unsafe&lt;/p&gt;' # Looks like you failed 2 tests of 4. t/03security.....dubious
The tests are:
# ---------------------------------------- is(despace $safe->filter_xml_fragment(qq( <p>unsafe</p><script )), '<p>unsafe</p>&lt;script', "HTML/XML entities"); # ---------------------------------------- is(despace $safe->filter_xml_fragment(qq( <p attr_ok="test>unsafe</p> )), '&lt;p attr_ok=&quot;test&gt;unsafe&lt;/p&gt;', "HTML/XML entities with incomplete tag"); --
Anybody knows if this is benign or not? My impression is that those two tests don't make sense, judging from the doc on filter_xml_fragment():

"Like above, but operates on the data as though it were well-formed XML. Use this if you intend on providing XHTML, for example."

The input isn't well-formed XML, so this sub is misused by the test. The sub builds a tree using HTML::TreeBuilder. Presumably, the behavior of this package has changed since HTML::Sanitizer was made and it doesn't treat ill-formed XML the way it used to.

Now that doesn't really tell us whether HTML::Sanitizer is usable as it is. However, the actual output given is that the ill-formed bits are discarded (instead of being escaped). I wouldn't think this creates an opportunity for cross-scripting so long as the user input is processed in one big chunk.. but your views would be very much appreciated.

david b
Direct Responses: Write a response
Perl Weekly newsletter
A free weekly newsletter for people who are busy to read all the blogs. click here to check it out.