X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FTemplate%2FPlugin%2FJavaScript.pm;h=16989e9a2d84f9e3396d72c1f86862c5663be2b5;hb=8be0f8a7ff52242c1b38345541796f66891735fa;hp=2e05bed57e981e3afffc48c7773595c1ece1b727;hpb=590c3aaa30805a3b5eb7c5f7ce18d893f85fe459;p=kivitendo-erp.git diff --git a/SL/Template/Plugin/JavaScript.pm b/SL/Template/Plugin/JavaScript.pm index 2e05bed57..16989e9a2 100644 --- a/SL/Template/Plugin/JavaScript.pm +++ b/SL/Template/Plugin/JavaScript.pm @@ -17,14 +17,23 @@ sub new { # public interface # +# see ecmascript spec section 7.8.4 +my @escape_chars = ('\\', '\'', '"'); +my %control_chars = ( + "\n" => 'n', + "\t" => 't', + "\r" => 'r', + "\f" => 'f', + "\x08" => 'b', + "\x0B" => 'v', # noone uses vertical tab anyway... +); +my $re = join '', map { qr/($_)/s } join '|', keys(%control_chars), map { "\Q$_\E" } @escape_chars; + sub escape { my $self = shift; my $text = shift; - $text =~ s|\\|\\\\|g; - $text =~ s|\"|\\\"|g; - $text =~ s|\n|\\n|g; - $text =~ s|\r|\\r|g; + $text =~ s/$re/'\\' . ($control_chars{$1} || $1)/egs; return $text; }