Permalink
Browse files

test invalid bareword

  • Loading branch information...
1 parent bd94b59 commit d73ea174c367911465a3b7223dfd36d7e3b06640 @kraih committed Mar 4, 2014
Showing with 9 additions and 6 deletions.
  1. +6 −6 lib/Mojo/JSON.pm
  2. +3 −0 t/mojo/json.t
View
@@ -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;
@@ -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';
View
@@ -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';

0 comments on commit d73ea17

Please sign in to comment.