noncharacter tests
This commit is contained in:
parent
c5c98482fc
commit
2720b2e0fb
2 changed files with 18 additions and 4 deletions
20
src/jsx.erl
20
src/jsx.erl
|
@ -174,10 +174,10 @@ jsx_decoder_gen([Test|_] = Tests, [Encoding|Encodings]) ->
|
||||||
Flags = proplists:get_value(jsx_flags, Test, []),
|
Flags = proplists:get_value(jsx_flags, Test, []),
|
||||||
{generator,
|
{generator,
|
||||||
fun() ->
|
fun() ->
|
||||||
[{Name, ?_assert(decode(JSON, Flags) =:= JSX)}
|
[{Name, ?_assertEqual(decode(JSON, Flags), JSX)}
|
||||||
| {generator,
|
| {generator,
|
||||||
fun() -> [{Name ++ " incremental", ?_assert(
|
fun() -> [{Name ++ " incremental", ?_assertEqual(
|
||||||
incremental_decode(JSON, Flags) =:= JSX)
|
incremental_decode(JSON, Flags), JSX)
|
||||||
} | jsx_decoder_gen(Tests, Encodings)]
|
} | jsx_decoder_gen(Tests, Encodings)]
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
@ -258,6 +258,20 @@ bad_escapes_test_() ->
|
||||||
},
|
},
|
||||||
{"escaped noncharacter",
|
{"escaped noncharacter",
|
||||||
?_assertEqual({error, badjson}, decode(<<"\"\\ud83f\\udfff\"">>, []))
|
?_assertEqual({error, badjson}, decode(<<"\"\\ud83f\\udfff\"">>, []))
|
||||||
|
},
|
||||||
|
{"noncharacter",
|
||||||
|
?_assertEqual({error, badjson}, decode(<<"\"\\uffff\"">>, []))
|
||||||
|
},
|
||||||
|
{"more noncharacters",
|
||||||
|
?_assertEqual({error, badjson}, decode(<<"\"\\ufdd0\"">>, []))
|
||||||
|
},
|
||||||
|
{"last noncharacter",
|
||||||
|
?_assertEqual({error, badjson}, decode(<<"\"\\ufdef\"">>, []))
|
||||||
|
},
|
||||||
|
{"ok character",
|
||||||
|
?_assertEqual([{string, <<239, 183, 176>>}, end_json],
|
||||||
|
decode(<<"\"\\ufdf0\"">>, [])
|
||||||
|
)
|
||||||
}
|
}
|
||||||
].
|
].
|
||||||
|
|
||||||
|
|
|
@ -466,7 +466,7 @@ escaped_unicode(<<D/?utfx, Rest/binary>>, Stack, Opts, String, [C, B, A])
|
||||||
X when X >= 16#d800, X =< 16#dbff ->
|
X when X >= 16#d800, X =< 16#dbff ->
|
||||||
low_surrogate(Rest, Stack, Opts, String, X)
|
low_surrogate(Rest, Stack, Opts, String, X)
|
||||||
%% non-characters, you're not allowed to exchange these
|
%% non-characters, you're not allowed to exchange these
|
||||||
; X when X == 16#fffe; X == 16#ffff ->
|
; X when X == 16#fffe; X == 16#ffff; X >= 16#fdd0, X =< 16#fdef ->
|
||||||
{error, {badjson, <<D/?utfx, Rest/binary>>}}
|
{error, {badjson, <<D/?utfx, Rest/binary>>}}
|
||||||
%% allowing interchange of null bytes allows attackers to forge
|
%% allowing interchange of null bytes allows attackers to forge
|
||||||
%% malicious streams
|
%% malicious streams
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue