From 776ee8a8a29f7dd456e51aadc9224d5d6a94381a Mon Sep 17 00:00:00 2001 From: alisdair sullivan Date: Wed, 3 Aug 2011 00:45:49 -0700 Subject: [PATCH] two new tests for bad low pairs of json surrogate pairs --- src/jsx_decoder.hrl | 18 +++++------------- test/cases/bad_low_surrogate.json | 1 + test/cases/bad_low_surrogate.test | 3 +++ test/cases/bad_low_surrogate_replaced.json | 1 + test/cases/bad_low_surrogate_replaced.test | 4 ++++ 5 files changed, 14 insertions(+), 13 deletions(-) create mode 100644 test/cases/bad_low_surrogate.json create mode 100644 test/cases/bad_low_surrogate.test create mode 100644 test/cases/bad_low_surrogate_replaced.json create mode 100644 test/cases/bad_low_surrogate_replaced.test 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]}.