Skip to content

Commit

Permalink
Merge pull request #81 from sile/fix-json-utf8-encoding-bug
Browse files Browse the repository at this point in the history
Fix `jsone:try_encode({{json_utf8, IncompleteUtf8}})` raises a `try_clause` exception.
  • Loading branch information
sile authored Sep 21, 2023
2 parents 8250f55 + caec6ba commit edff49e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ jobs:
runs-on: ${{matrix.os}}
strategy:
matrix:
otp: ['24.0', '25.0']
otp: ['24.0', '25.0', '26.0']
os: [ubuntu-latest]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: erlef/setup-beam@v1
with:
otp-version: ${{matrix.otp}}
Expand All @@ -31,7 +31,7 @@ jobs:
needs: ci
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: erlef/setup-beam@v1
with:
otp-version: '25.0'
Expand Down
3 changes: 3 additions & 0 deletions src/jsone_encode.erl
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ value({{json_utf8, T}}, Nexts, Buf, Opt) ->
{error, OK, Invalid} ->
{error, {{invalid_json_utf8, OK, Invalid},
[{?MODULE, value, [{json_utf8, T}, Nexts, Buf, Opt], [{line, ?LINE}]}]}};
{incomplete, OK, Incomplete} ->
{error, {{invalid_json_utf8, OK, Incomplete},
[{?MODULE, value, [{json_utf8, T}, Nexts, Buf, Opt], [{line, ?LINE}]}]}};
B when is_binary(B) ->
next(Nexts, <<Buf/binary, B/binary>>, Opt)
catch
Expand Down
6 changes: 5 additions & 1 deletion test/jsone_encode_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ encode_test_() ->
<<"bar">>,
{{json, [$", 233, "ok", $"]}}))),
?assertEqual({ok, <<"{\"json\":\"[1,2,3]\"}">>}, jsone_encode:encode([{json, <<"[1,2,3]">>}])),
?assertEqual({ok, <<"[[1,2,3]]">>}, jsone_encode:encode([{{json, <<"[1,2,3]">>}}]))
?assertEqual({ok, <<"[[1,2,3]]">>}, jsone_encode:encode([{{json, <<"[1,2,3]">>}}])),

%% Errors
?assertMatch({error, {{invalid_json_utf8, _, _}, _}}, jsone_encode:encode({{json_utf8, <<200, 83, 1>>}})),
?assertMatch({error, {{invalid_json_utf8, _, _}, _}}, jsone_encode:encode({{json_utf8, <<"abc", 192>>}}))
end},
%% Numbers: Integer
{"zero", fun() -> ?assertEqual({ok, <<"0">>}, jsone_encode:encode(0)) end},
Expand Down

0 comments on commit edff49e

Please sign in to comment.