X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;ds=sidebyside;f=SL%2FHTML%2FUtil.pm;h=f68fb0a1f8d93cf04a4f46bd722eadba0d7134d1;hb=d4925a8b60f04674885e30d9316dc0263f8b9a84;hp=7212d646ffef763f22744972b07bf45b9c66c717;hpb=792ae733e8f54eca6d306ad523a7a6e166fcb0e0;p=kivitendo-erp.git diff --git a/SL/HTML/Util.pm b/SL/HTML/Util.pm index 7212d646f..f68fb0a1f 100644 --- a/SL/HTML/Util.pm +++ b/SL/HTML/Util.pm @@ -6,12 +6,24 @@ use warnings; use HTML::Parser; my %stripper; +my %entities = ( + '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 { my ($class_or_value) = @_; 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 ); @@ -22,6 +34,8 @@ sub strip { $stripper{parser}->parse($value); $stripper{parser}->eof; + $stripper{text} =~ s{\&([^;]+);}{ $entities{$1} || "\&$1;" }eg; + return delete $stripper{text}; }