Bug 19655: Make To.json escape doesn't escape newlines to create valid JSON
[koha.git] / Koha / Template / Plugin / To.pm
index 6bf56b1..f87a39c 100644 (file)
@@ -29,6 +29,8 @@ sub json {
     my $json = JSON->new->allow_nonref(1);
     $json = $json->encode($value);
     $json =~ s/^"|"$//g; # Remove quotes around the strings
+    $json =~ s/\\r/\\\\r/g; # Convert newlines to escaped newline characters
+    $json =~ s/\\n/\\\\n/g;
     return $json;
 }