Subject: | newlines in string data creates incorrect javascript |
Data-JavaScript-Anon-0.4
Linux 2.4.18-27.8.0 (Red Hat Linux release 8.0 (Psyche))
This is perl, v5.8.0 built for i386-linux-thread-multi
Its a great module... thanks!
Here is my problem:
the problem:
demo script:
use Data::JavaScript::Anon;
my $data = "foo\nbar";
print Data::JavaScript::Anon->anon_dump( $data );
outputs:
"foo
bar"
wrapped in html and loaded in a browser (firefox, ie6(win)):
<html><head><script>
var data = "foo
bar";
</script></head></html>
Error: "Unterminated string literal"
The fix:
in anon_scalar change the escaper regex to
$value =~ s/(\\|\"|\r|\n)/\\$1/g;