Skip to content

Commit

Permalink
test invalid bareword
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Mar 4, 2014
1 parent bd94b59 commit d73ea17
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/Mojo/JSON.pm
Expand Up @@ -195,12 +195,12 @@ sub _decode_value {
# String
return _decode_string() if m/\G"/gc;

# Array
return _decode_array() if m/\G\[/gc;

# Object
return _decode_object() if m/\G\{/gc;

# Array
return _decode_array() if m/\G\[/gc;

# Number
return 0 + $1
if m/\G([-]?(?:0|[1-9][0-9]*)(?:\.[0-9]*)?(?:[eE][+-]?[0-9]+)?)/gc;
Expand Down Expand Up @@ -242,12 +242,12 @@ sub _encode_value {
# Reference
if (my $ref = ref $value) {

# Array
return _encode_array($value) if $ref eq 'ARRAY';

# Object
return _encode_object($value) if $ref eq 'HASH';

# Array
return _encode_array($value) if $ref eq 'ARRAY';

# True or false
return $$value ? 'true' : 'false' if $ref eq 'SCALAR';
return $value ? 'true' : 'false' if $ref eq 'Mojo::JSON::_Bool';
Expand Down
3 changes: 3 additions & 0 deletions t/mojo/json.t
Expand Up @@ -308,6 +308,9 @@ like $json->encode({test => -sin(9**9**9)}), qr/^{"test":".*"}$/,
'encode "nan" as string';

# Errors
is $json->decode('test'), undef, 'syntax error';
is $json->error, 'Malformed JSON: Expected string, array, object, number,'
. ' boolean or null at line 0, offset 0', 'right error';
is $json->decode('["♥"]'), undef, 'wide character in input';
is $json->error, 'Wide character in input', 'right error';
is $json->decode(b('["\\ud800"]')->encode), undef, 'syntax error';
Expand Down

0 comments on commit d73ea17

Please sign in to comment.