diff --git a/src/jsx_decoder.hrl b/src/jsx_decoder.hrl index ac40cfa..537fb84 100644 --- a/src/jsx_decoder.hrl +++ b/src/jsx_decoder.hrl @@ -568,7 +568,8 @@ escaped_unicode(Bin, Stack, Opts, String, Acc) -> low_surrogate(<>, 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(<> = Bin, Stack, Opts, String, _) -> case Opts#opts.loose_unicode of true -> @@ -608,15 +609,10 @@ low_surrogate(<>, 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, <>}} end @@ -627,11 +623,7 @@ low_surrogate(<>, 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, <>}} end diff --git a/test/cases/bad_low_surrogate.json b/test/cases/bad_low_surrogate.json new file mode 100644 index 0000000..4b22b57 --- /dev/null +++ b/test/cases/bad_low_surrogate.json @@ -0,0 +1 @@ +["\ud801\u0032"] \ No newline at end of file diff --git a/test/cases/bad_low_surrogate.test b/test/cases/bad_low_surrogate.test new file mode 100644 index 0000000..9f36e55 --- /dev/null +++ b/test/cases/bad_low_surrogate.test @@ -0,0 +1,3 @@ +{name, "bad_low_surrogate"}. +{jsx, {error, badjson}}. +{json, "bad_low_surrogate.json"}. diff --git a/test/cases/bad_low_surrogate_replaced.json b/test/cases/bad_low_surrogate_replaced.json new file mode 100644 index 0000000..4b22b57 --- /dev/null +++ b/test/cases/bad_low_surrogate_replaced.json @@ -0,0 +1 @@ +["\ud801\u0032"] \ No newline at end of file diff --git a/test/cases/bad_low_surrogate_replaced.test b/test/cases/bad_low_surrogate_replaced.test new file mode 100644 index 0000000..2fc7b3d --- /dev/null +++ b/test/cases/bad_low_surrogate_replaced.test @@ -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]}.