From be5cae093b3218e8a1dcaa31911a43781ea3261f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Wed, 27 Dec 2017 11:08:52 +0100 Subject: [PATCH] =?utf8?q?Presenter::EscapedText:=20quote=5Fhtml=20nicht?= =?utf8?q?=20=C3=BCber=20$::locale=20laufen=20lassen?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Die quote_html Liste in speacial_chars ist extrem langsam. Für HTML Generierung lieber diese optimierte nehmen. --- SL/Presenter/EscapedText.pm | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/SL/Presenter/EscapedText.pm b/SL/Presenter/EscapedText.pm index 2fc04fdeb..ca3c8ca62 100644 --- a/SL/Presenter/EscapedText.pm +++ b/SL/Presenter/EscapedText.pm @@ -10,6 +10,14 @@ use JSON (); use overload '""' => \&escaped_text; +my %html_entities = ( + '<' => '<', + '>' => '>', + '&' => '&', + '"' => '"', + "'" => ''', +); + # static constructors sub new { my ($class, %params) = @_; @@ -17,11 +25,17 @@ sub new { return $params{text} if ref($params{text}) eq $class; my $self = bless {}, $class; - $self->{text} = $params{is_escaped} ? $params{text} : $::locale->quote_special_chars('HTML', $params{text}); + $self->{text} = $params{is_escaped} ? $params{text} : quote_html($params{text}); return $self; } +sub quote_html { + return undef unless defined $_[0]; + (my $x = $_[0]) =~ s/(["'<>&])/$html_entities{$1}/ge; + $x +} + sub escape { __PACKAGE__->new(text => $_[0]); } -- 2.20.1