test for noncharacters, fixed bug discovered by test

This commit is contained in:
alisdair sullivan 2011-07-26 19:28:41 -07:00
parent 4ba8c4d57e
commit c5c98482fc
2 changed files with 18 additions and 3 deletions

View file

@ -232,7 +232,9 @@ decode_loop({jsx, end_json, _Next}, Acc) ->
decode_loop({jsx, incomplete, More}, Acc) ->
decode_loop(More(end_stream), Acc);
decode_loop({jsx, E, Next}, Acc) ->
decode_loop(Next(), [E] ++ Acc).
decode_loop(Next(), [E] ++ Acc);
decode_loop({error, {badjson, _Error}}, _Acc) ->
{error, badjson}.
incremental_decode(<<C:1/binary, Rest/binary>>, Flags) ->
@ -249,6 +251,17 @@ incremental_decode_loop({jsx, Event, Next}, Rest, Acc) ->
incremental_decode_loop(Next(), Rest, [Event] ++ Acc).
bad_escapes_test_() ->
[
{"null byte",
?_assertEqual({error, badjson}, decode(<<"\"\\u0000\"">>, []))
},
{"escaped noncharacter",
?_assertEqual({error, badjson}, decode(<<"\"\\ud83f\\udfff\"">>, []))
}
].
multi_decode_test_() ->
[
{"multiple values in a single stream", ?_assert(
@ -291,4 +304,5 @@ multi_test_result() ->
-endif.

View file

@ -542,9 +542,10 @@ low_surrogate(<<D/?utfx, Rest/binary>>, Stack, Opts, String, [C, B, A], High)
X when X >= 16#dc00, X =< 16#dfff ->
V = surrogate_to_codepoint(High, X),
case V rem 16#10000 of
X when X == 16#fffe; X == 16#ffff ->
Y when Y == 16#fffe; Y == 16#ffff ->
{error, {badjson, <<D/?utfx, Rest/binary>>}}
; _ ->
; Y ->
io:format("~p ~p~n", [V, Y]),
string(Rest, Stack, Opts, <<String/binary, V/utf8>>)
end
%% not a low surrogate, bad bad bad