diff --git a/src/jsx_utils.erl b/src/jsx_utils.erl index 5c70797..8f1eaf9 100644 --- a/src/jsx_utils.erl +++ b/src/jsx_utils.erl @@ -225,9 +225,7 @@ json_escape(<<$\t, Rest/binary>>, Opts, Acc) -> json_escape(<>, Opts, Acc) when C >= 0, C < $\s -> json_escape(Rest, Opts, - <> + <> ); %% escape forward slashes -- optionally -- to faciliate microsoft's retarded %% date format @@ -238,24 +236,11 @@ json_escape(<>, Opts, Acc) when C == 16#2028; C == 16#2029 -> json_escape(Rest, Opts, - <> + <> ); %% any other legal codepoint json_escape(<>, Opts, Acc) -> json_escape(Rest, Opts, <>); -%% if loose_unicode is true, replace illegal sequences with u+fffd -%% u+fffe and u+ffff -json_escape(<<239, 191, X, Rest/binary>>, Opts=#opts{loose_unicode=true}, Acc) - when X == 190; X == 191 -> - json_escape(Rest, Opts, <>); -%% surrogates -json_escape(<<237, X, _, Rest/binary>>, Opts=#opts{loose_unicode=true}, Acc) - when X >= 160 -> - json_escape(Rest, Opts, <>); -json_escape(<<_, Rest/binary>>, Opts=#opts{loose_unicode=true}, Acc) -> - json_escape(Rest, Opts, <>); json_escape(<<>>, _Opts, Acc) -> Acc; json_escape(Rest, Opts, Acc) -> @@ -268,7 +253,6 @@ json_escape_sequence(X) -> [$\\, $u, (to_hex(A)), (to_hex(B)), (to_hex(C)), (to_hex(D))]. - to_hex(10) -> $a; to_hex(11) -> $b; to_hex(12) -> $c; @@ -345,13 +329,6 @@ binary_escape_test_() -> #opts{escape_forward_slash=true} ) =:= <<"\\/Date(1303502009425)\\/">> ) - }, - %% <<239, 191, 191>> is u+ffff - {"loose unicode", - ?_assert(json_escape(<<"hi there "/utf8, 239, 191, 191, "!"/utf8>>, - #opts{loose_unicode=true} - ) =:= <<"hi there "/utf8, 16#fffd/utf8, "!"/utf8>> - ) } ].