Bug 19655: Make To.json escape doesn't escape newlines to create valid JSON

JSON does not allow real line-breaks. If a field contains them and they are not escaped, a JSON parser will be unable to convert the stringified JSON back into an object.

This is clearly exemplified by the guarantor search, where a multi-line note on the guarantor's record will break the ability to select that guarantor.

Test Plan:
1) Create Patron A with a "Circulation note" that has multiple lines in it
2) Create Patron B
3) Attempt to set Patron A to be the guarantor for Patron B
4) Note selecting the patron does nothing
5) Apply this patch
6) Repeat step 3
7) Selecting the guarantor now works!

Signed-off-by: Simon Pouchol <simon.pouchol@biblibre.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
(cherry picked from commit 9cd9240c36)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
Kyle M Hall 2017-11-20 11:05:35 -05:00 committed by Fridolin Somers
parent f2a828d551
commit efb28c4af1
1 changed files with 2 additions and 0 deletions

View 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;
}