From: Sven Schöling Date: Mon, 21 Jul 2014 09:08:44 +0000 (+0200) Subject: HTML::Util: Tests, und Bugfixes für ein paar Randbedingungen X-Git-Tag: release-3.2.0beta~392 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=06a0f32d8602a6b79e51b0fcd51edb67e780a003;p=kivitendo-erp.git HTML::Util: Tests, und Bugfixes für ein paar Randbedingungen --- diff --git a/SL/HTML/Util.pm b/SL/HTML/Util.pm index ed5ffdec9..c62fd9202 100644 --- a/SL/HTML/Util.pm +++ b/SL/HTML/Util.pm @@ -17,7 +17,10 @@ sub strip { my $value = !ref($class_or_value) && (($class_or_value // '') eq 'SL::HTML::Util') ? $_[1] : $class_or_value; - return '' unless $value; + return '' unless defined $value; + + # Remove HTML comments. + $value =~ s{ }{}gx; if (!%stripper) { %stripper = ( parser => HTML::Parser->new ); diff --git a/t/html/util.t b/t/html/util.t new file mode 100644 index 000000000..1b9bb80ab --- /dev/null +++ b/t/html/util.t @@ -0,0 +1,24 @@ +use Test::More; + +use_ok 'SL::HTML::Util'; + +sub test { + is(SL::HTML::Util::strip($_[0]), $_[1], "$_[2] (direct invocation)"); + is(SL::HTML::Util->strip($_[0]), $_[1], "$_[2] (class invocation)"); +} + +test undef, '', 'undef'; +test 0, '0', '0'; +test '0 but true', '0 but true', 'zero but true'; +test '

title

', 'title', 'standard case'; +test '

title

', 'title', 'imbalanced html'; +test 'walter & walter', 'walter & walter', 'known entities'; +test 'Walter&Walter; Chicago', 'Walter&Walter; Chicago', 'unknown entities'; +test '

title -->title', 'title', 'nested stuff in html comments'; + +done_testing;