Revision 06a0f32d
Von Sven Schöling vor mehr als 10 Jahren hinzugefügt
SL/HTML/Util.pm | ||
---|---|---|
17 | 17 |
|
18 | 18 |
my $value = !ref($class_or_value) && (($class_or_value // '') eq 'SL::HTML::Util') ? $_[1] : $class_or_value; |
19 | 19 |
|
20 |
return '' unless $value; |
|
20 |
return '' unless defined $value; |
|
21 |
|
|
22 |
# Remove HTML comments. |
|
23 |
$value =~ s{ <!-- .*? --> }{}gx; |
|
21 | 24 |
|
22 | 25 |
if (!%stripper) { |
23 | 26 |
%stripper = ( parser => HTML::Parser->new ); |
t/html/util.t | ||
---|---|---|
1 |
use Test::More; |
|
2 |
|
|
3 |
use_ok 'SL::HTML::Util'; |
|
4 |
|
|
5 |
sub test { |
|
6 |
is(SL::HTML::Util::strip($_[0]), $_[1], "$_[2] (direct invocation)"); |
|
7 |
is(SL::HTML::Util->strip($_[0]), $_[1], "$_[2] (class invocation)"); |
|
8 |
} |
|
9 |
|
|
10 |
test undef, '', 'undef'; |
|
11 |
test 0, '0', '0'; |
|
12 |
test '0 but true', '0 but true', 'zero but true'; |
|
13 |
test '<h1>title</h1>', 'title', 'standard case'; |
|
14 |
test '<h1>title</h2>', 'title', 'imbalanced html'; |
|
15 |
test 'walter & walter', 'walter & walter', 'known entities'; |
|
16 |
test 'Walter&Walter; Chicago', 'Walter&Walter; Chicago', 'unknown entities'; |
|
17 |
test '<h1>title</h1', 'title', 'invalid html 1'; |
|
18 |
|
|
19 |
# This happens when someone copies a block from MS Word. The HTML that is |
|
20 |
# generated contains style information in comments. These styles can contain |
|
21 |
# sgml. HTML::Parser does not handle these properly. |
|
22 |
test '<!-- style: <> -->title', 'title', 'nested stuff in html comments'; |
|
23 |
|
|
24 |
done_testing; |
Auch abrufbar als: Unified diff
HTML::Util: Tests, und Bugfixes für ein paar Randbedingungen