From d27b077e63ceda8fb3a2b9d3e16f93ab14d0a872 Mon Sep 17 00:00:00 2001 From: miker Date: Thu, 25 Aug 2005 21:32:22 +0000 Subject: [PATCH] protect hash keys by quoting git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@507 9efc2488-bf62-4759-914b-345cdb29e865 --- src/perlmods/JSON.pm | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/perlmods/JSON.pm b/src/perlmods/JSON.pm index a43f48f..8ec0c4c 100644 --- a/src/perlmods/JSON.pm +++ b/src/perlmods/JSON.pm @@ -195,8 +195,16 @@ sub perl2JSON { my $c = 0; for my $key (sort keys %$perl) { $output .= ',' if ($c); - - $output .= '"'.$key.'":'.perl2JSON(undef,$$perl{$key}, $strict); + + $key =~ s{\\}{\\\\}sgo; + $key =~ s/"/\\"/sgo; + $key =~ s/\t/\\t/sgo; + $key =~ s/\f/\\f/sgo; + $key =~ s/\r/\\r/sgo; + $key =~ s/\n/\\n/sgo; + $key =~ s/(\pM)/sprintf('\u%0.4x',ord($1))/sgoe; + + $output .= '"'.$key.'":'.key2JSON(undef,$$perl{$key}, $strict); $c++; } $output .= '}'; -- 2.11.0