diff --git a/src/njson.erl b/src/njson.erl index d4206c1..7913c6d 100644 --- a/src/njson.erl +++ b/src/njson.erl @@ -20,8 +20,14 @@ -type t() :: null | boolean() | number() | binary() | [t()] | #{binary() => t()}. -type decode_error_reason() :: - invalid_value | unexpected_trailing_char | invalid_key | invalid_array | invalid_object. --type decode_error() :: {error, {decode_error_reason(), [byte()], non_neg_integer()}}. + invalid_value + | unexpected_trailing_char + | invalid_key + | invalid_array + | invalid_object + | unexpected_end_of_string. +-type decode_error() :: + {error, {decode_error_reason(), [byte()], non_neg_integer()}}. -type encode_error_reason() :: invalid_key | invalid_value | invalid_map | invalid_list. -type encode_error() :: {error, {encode_error_reason(), any()}}. diff --git a/src/njson_decoder.erl b/src/njson_decoder.erl index 8cf0240..2f6bceb 100644 --- a/src/njson_decoder.erl +++ b/src/njson_decoder.erl @@ -388,6 +388,8 @@ string(<>, Original, Skip, Next, Len) -> OK :: {ok, Json}, Json :: njson:t(), Error :: njson:decode_error(). +chunk(<<>>, _Original, Skip, _Next, _Len) -> + {error, {unexpected_end_of_string, [], Skip}}; chunk(<>, Original, Skip, Next, Len) -> case C of $" -> @@ -407,6 +409,8 @@ chunk(<>, Original, Skip, Next, Len) -> OK :: {ok, Json}, Json :: njson:t(), Error :: njson:decode_error(). +chunk(<<>>, _Original, Skip, _Next, _Len, _Acc) -> + {error, {unexpected_end_of_string, [], Skip}}; chunk(<>, Original, Skip, Next, Len, Acc) -> case C of $" ->