Skip to content

Commit

Permalink
fixed backslash encoding bug in Mojo::JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Dec 23, 2009
1 parent e6a9060 commit 6c306e2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ This file documents the revision history for Perl extension Mojo.
- Made param decoding more defensive and allow malformed data to pass
through for debugging.
- Reduced Mojolicious log output outside of development mode.
- Fixed backslash encoding bug in Mojo::JSON.
- Fixed memory leaks in Mojolicious plugins. (sharifulin)
- Fixed makefile and app generators.
- Fixed a case where an ending tag would be interpreted as a line
Expand Down
16 changes: 8 additions & 8 deletions lib/Mojo/JSON.pm
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ my $VALUE_SEPARATOR_RE = qr/^$WHITESPACE_RE\,/;

# Escaped special character map
my $ESCAPE = {
'\"' => "\x22",
'\\' => "\x5c",
'\/' => "\x2f",
'\b' => "\x8",
'\f' => "\xC",
'\n' => "\xA",
'\r' => "\xD",
'\t' => "\x9"
'\"' => "\x22",
'\\\\' => "\x5c",
'\/' => "\x2f",
'\b' => "\x8",
'\f' => "\xC",
'\n' => "\xA",
'\r' => "\xD",
'\t' => "\x9"
};
my $REVERSE_ESCAPE = {};
for my $key (keys %$ESCAPE) { $REVERSE_ESCAPE->{$ESCAPE->{$key}} = $key }
Expand Down
8 changes: 7 additions & 1 deletion t/mojo/json.t
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use strict;
use warnings;

use Test::More tests => 92;
use Test::More tests => 94;

use Mojo::ByteStream 'b';

Expand Down Expand Up @@ -212,6 +212,12 @@ $string = $json->encode($array);
ok($string);
is_deeply($json->decode($string), $array);

# Real world roundtrip
$string = $json->encode({foo => 'c:\progra~1\mozill~1\firefox.exe'});
is($string, '{"foo":"c:\\\\progra~1\\\\mozill~1\\\\firefox.exe"}');
$hash = $json->decode($string);
is_deeply($hash, {foo => 'c:\progra~1\mozill~1\firefox.exe'});

# Errors
is($json->decode('[[]'), undef);
is($json->error, 'Missing right square bracket near end of file.');
Expand Down

0 comments on commit 6c306e2

Please sign in to comment.