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