Skip to content

Commit

Permalink
fixed small bug in Mojo::JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Aug 23, 2011
1 parent f7193f7 commit fb657af
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions Changes
Expand Up @@ -2,6 +2,7 @@ This file documents the revision history for Perl extension Mojolicious.

1.88 2011-08-23 00:00:00
- Added EXPERIMENTAL split method to Mojo::ByteStream.
- Fixed small bug in Mojo::JSON.

1.87 2011-08-23 00:00:00
- Added EXPERIMENTAL app method to Mojo::Command.
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/JSON.pm
Expand Up @@ -66,7 +66,7 @@ sub decode {

# Wide characters
$self->error('Wide character in input.') and return
unless utf8::downgrade($_, 1);
unless utf8::downgrade($string, 1);

# Detect and decode unicode
my $encoding = 'UTF-8';
Expand Down
6 changes: 5 additions & 1 deletion t/mojo/json.t
@@ -1,9 +1,11 @@
#!/usr/bin/env perl
use Mojo::Base -strict;

use utf8;

use Test::More;
plan skip_all => 'Perl 5.10 required for this test!' unless $] >= 5.010;
plan tests => 116;
plan tests => 118;

use Mojo::ByteStream 'b';

Expand Down Expand Up @@ -256,6 +258,8 @@ $string = $json->encode([b('test')]);
is_deeply $json->decode($string), ['test'], 'right roundtrip';

# Errors
is $json->decode('["♥"]'), undef, 'wide character in input';
is $json->error, 'Wide character in input.', 'right error';
is $json->decode(b("\x{feff}[\"\\ud800\"]")->encode('UTF-16LE')), undef,
'missing high surrogate';
is $json->error,
Expand Down

0 comments on commit fb657af

Please sign in to comment.