X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FTemplate%2FPlugin%2FJavaScript.pm;h=16989e9a2d84f9e3396d72c1f86862c5663be2b5;hb=abafb475d9742e3a6c28427477235c923b21eeef;hp=2e05bed57e981e3afffc48c7773595c1ece1b727;hpb=abb20e95654d2a427bd596b571c3327a5a353b26;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; }