projects
/
kivitendo-erp.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
PayPostingImport: Testfall zu d32410ac096b angepasst
[kivitendo-erp.git]
/
SL
/
HTML
/
Util.pm
diff --git
a/SL/HTML/Util.pm
b/SL/HTML/Util.pm
index
72a7a7f
..
a54425d
100644
(file)
--- a/
SL/HTML/Util.pm
+++ b/
SL/HTML/Util.pm
@@
-7,9
+7,11
@@
use HTML::Parser;
my %stripper;
my %entities = (
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 {
);
sub strip {
@@
-17,10
+19,15
@@
sub strip {
my $value = !ref($class_or_value) && (($class_or_value // '') eq 'SL::HTML::Util') ? $_[1] : $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 );
if (!%stripper) {
%stripper = ( parser => HTML::Parser->new );
- $stripper{parser}->handler(text => sub { $stripper{text} .= $_[1]; });
+ $stripper{parser}->handler(text => sub { $stripper{text} .=
' ' .
$_[1]; });
}
$stripper{text} = '';
}
$stripper{text} = '';
@@
-28,6
+35,8
@@
sub strip {
$stripper{parser}->eof;
$stripper{text} =~ s{\&([^;]+);}{ $entities{$1} || "\&$1;" }eg;
$stripper{parser}->eof;
$stripper{text} =~ s{\&([^;]+);}{ $entities{$1} || "\&$1;" }eg;
+ $stripper{text} =~ s{^ +| +$}{}g;
+ $stripper{text} =~ s{ {2,}}{ }g;
return delete $stripper{text};
}
return delete $stripper{text};
}