From 06a0f32d8602a6b79e51b0fcd51edb67e780a003 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Mon, 21 Jul 2014 11:08:44 +0200 Subject: [PATCH] =?utf8?q?HTML::Util:=20Tests,=20und=20Bugfixes=20f=C3=BCr?= =?utf8?q?=20ein=20paar=20Randbedingungen?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/HTML/Util.pm | 5 ++++- t/html/util.t | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 t/html/util.t 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; -- 2.20.1