two new tests for bad low pairs of json surrogate pairs
This commit is contained in:
parent
5cd967b26d
commit
776ee8a8a2
5 changed files with 14 additions and 13 deletions
|
@ -568,7 +568,8 @@ escaped_unicode(Bin, Stack, Opts, String, Acc) ->
|
|||
|
||||
low_surrogate(<<?rsolidus/?utfx, Rest/binary>>, Stack, Opts, String, High) ->
|
||||
low_surrogate_u(Rest, Stack, Opts, String, High);
|
||||
%% not an escaped codepoint, our high codepoint is illegal
|
||||
%% not an escaped codepoint, our high codepoint is illegal. dispatch back to
|
||||
%% string to handle
|
||||
low_surrogate(<<S/?utfx, Rest/binary>> = Bin, Stack, Opts, String, _) ->
|
||||
case Opts#opts.loose_unicode of
|
||||
true ->
|
||||
|
@ -608,15 +609,10 @@ low_surrogate(<<D/?utfx, Rest/binary>>, Stack, Opts, String, [C, B, A], H)
|
|||
case erlang:list_to_integer([A, B, C, D], 16) of
|
||||
X when X >= 16#dc00, X =< 16#dfff ->
|
||||
V = surrogate_to_codepoint(H, X),
|
||||
case V rem 16#10000 of
|
||||
Y when Y == 16#fffe; Y == 16#ffff ->
|
||||
case V rem 16#10000 of Y when Y == 16#fffe; Y == 16#ffff ->
|
||||
case Opts#opts.loose_unicode of
|
||||
true ->
|
||||
string(Rest,
|
||||
Stack,
|
||||
Opts,
|
||||
[16#fffd] ++ String
|
||||
)
|
||||
string(Rest, Stack, Opts, [16#fffd] ++ String)
|
||||
; false ->
|
||||
{error, {badjson, <<D/?utfx, Rest/binary>>}}
|
||||
end
|
||||
|
@ -627,11 +623,7 @@ low_surrogate(<<D/?utfx, Rest/binary>>, Stack, Opts, String, [C, B, A], H)
|
|||
; _ ->
|
||||
case Opts#opts.loose_unicode of
|
||||
true ->
|
||||
string(Rest,
|
||||
Stack,
|
||||
Opts,
|
||||
[16#fffd, 16#fffd] ++ String
|
||||
)
|
||||
string(Rest, Stack, Opts, [16#fffd, 16#fffd] ++ String)
|
||||
; false ->
|
||||
{error, {badjson, <<D/?utfx, Rest/binary>>}}
|
||||
end
|
||||
|
|
1
test/cases/bad_low_surrogate.json
Normal file
1
test/cases/bad_low_surrogate.json
Normal file
|
@ -0,0 +1 @@
|
|||
["\ud801\u0032"]
|
3
test/cases/bad_low_surrogate.test
Normal file
3
test/cases/bad_low_surrogate.test
Normal file
|
@ -0,0 +1,3 @@
|
|||
{name, "bad_low_surrogate"}.
|
||||
{jsx, {error, badjson}}.
|
||||
{json, "bad_low_surrogate.json"}.
|
1
test/cases/bad_low_surrogate_replaced.json
Normal file
1
test/cases/bad_low_surrogate_replaced.json
Normal file
|
@ -0,0 +1 @@
|
|||
["\ud801\u0032"]
|
4
test/cases/bad_low_surrogate_replaced.test
Normal file
4
test/cases/bad_low_surrogate_replaced.test
Normal file
|
@ -0,0 +1,4 @@
|
|||
{name, "bad_low_surrogate_replaced"}.
|
||||
{jsx, [start_array,{string, [16#fffd, 16#fffd]},end_array,end_json]}.
|
||||
{json, "bad_low_surrogate_replaced.json"}.
|
||||
{jsx_flags, [loose_unicode]}.
|
Loading…
Add table
Add a link
Reference in a new issue