Skip to content

Commit

Permalink
fix: error when incomplete strings. (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrrubinos authored Dec 3, 2023
1 parent 338ecba commit d1f954a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/njson.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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()}}.
Expand Down
4 changes: 4 additions & 0 deletions src/njson_decoder.erl
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,8 @@ string(<<Bin/binary>>, 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(<<C, Bin/binary>>, Original, Skip, Next, Len) ->
case C of
$" ->
Expand All @@ -407,6 +409,8 @@ chunk(<<C, Bin/binary>>, 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(<<C, Bin/binary>>, Original, Skip, Next, Len, Acc) ->
case C of
$" ->
Expand Down

0 comments on commit d1f954a

Please sign in to comment.