X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FHTML%2FUtil.pm;h=f68fb0a1f8d93cf04a4f46bd722eadba0d7134d1;hb=2f5ea2de698efeaf8e7c31dcbc27b4e996f5e2ca;hp=0b2e630d00d227829ee6e7835f28489c1bb66a74;hpb=5de9f9f8e33b1fe8ab69cf38bc58d74cbec81779;p=kivitendo-erp.git diff --git a/SL/HTML/Util.pm b/SL/HTML/Util.pm index 0b2e630d0..f68fb0a1f 100644 --- a/SL/HTML/Util.pm +++ b/SL/HTML/Util.pm @@ -7,9 +7,11 @@ use HTML::Parser; my %stripper; my %entities = ( - 'lt' => '<', - 'gt' => '>', - 'amp' => '&', + 'lt' => '<', + 'gt' => '>', + 'amp' => '&', + 'nbsp' => ' ', # should be => "\x{00A0}", but this can lead to problems with + # a non-visible character in csv-exports for example ); sub strip { @@ -17,6 +19,11 @@ sub strip { my $value = !ref($class_or_value) && (($class_or_value // '') eq 'SL::HTML::Util') ? $_[1] : $class_or_value; + return '' unless defined $value; + + # Remove HTML comments. + $value =~ s{ }{}gx; + if (!%stripper) { %stripper = ( parser => HTML::Parser->new ); @@ -27,7 +34,7 @@ sub strip { $stripper{parser}->parse($value); $stripper{parser}->eof; - $stripper{text} =~ s{\&([^;]+);}{ $entities{$1} }eg; + $stripper{text} =~ s{\&([^;]+);}{ $entities{$1} || "\&$1;" }eg; return delete $stripper{text}; }