restrict escaped codepoint conversion from inserting invalid codepoints into strings
This commit is contained in:
parent
5f5be51365
commit
46d859c6d0
1 changed files with 10 additions and 5 deletions
15
src/jsx.erl
15
src/jsx.erl
|
@ -304,9 +304,9 @@ escape(<<>>, Stack, Callbacks, Opts, Acc) ->
|
||||||
%% codepoint sequences. if the ascii option is present, the sequence is converted
|
%% codepoint sequences. if the ascii option is present, the sequence is converted
|
||||||
%% to a codepoint and inserted into the string if it represents an ascii value. if
|
%% to a codepoint and inserted into the string if it represents an ascii value. if
|
||||||
%% the codepoint option is present the sequence is converted and inserted as long
|
%% the codepoint option is present the sequence is converted and inserted as long
|
||||||
%% as it represents a valid 16 bit integer value (this is where json's spec gets
|
%% as it represents a valid unicode codepoint. this means non-characters
|
||||||
%% insane). any other option and the sequence is converted back to an erlang string
|
%% representable in 16 bits are not converted (the utf16 surrogates and the two
|
||||||
%% and appended to the string in place.
|
%% special non-characters). any other option and no conversion is done.
|
||||||
|
|
||||||
escaped_unicode(<<D, Rest/binary>>,
|
escaped_unicode(<<D, Rest/binary>>,
|
||||||
Stack,
|
Stack,
|
||||||
|
@ -316,7 +316,7 @@ escaped_unicode(<<D, Rest/binary>>,
|
||||||
[C, B, A])
|
[C, B, A])
|
||||||
when ?is_hex(D) ->
|
when ?is_hex(D) ->
|
||||||
case erlang:list_to_integer([A, B, C, D], 16) of
|
case erlang:list_to_integer([A, B, C, D], 16) of
|
||||||
X when X < 127 ->
|
X when X < 128 ->
|
||||||
string(Rest, Stack, Callbacks, Opts, [X] ++ String)
|
string(Rest, Stack, Callbacks, Opts, [X] ++ String)
|
||||||
; _ ->
|
; _ ->
|
||||||
string(Rest, Stack, Callbacks, Opts, [D, C, B, A, $u, ?rsolidus] ++ String)
|
string(Rest, Stack, Callbacks, Opts, [D, C, B, A, $u, ?rsolidus] ++ String)
|
||||||
|
@ -328,7 +328,12 @@ escaped_unicode(<<D, Rest/binary>>,
|
||||||
String,
|
String,
|
||||||
[C, B, A])
|
[C, B, A])
|
||||||
when ?is_hex(D) ->
|
when ?is_hex(D) ->
|
||||||
string(Rest, Stack, Callbacks, Opts, [erlang:list_to_integer([A, B, C, D], 16)] ++ String);
|
case erlang:list_to_integer([A, B, C, D], 16) of
|
||||||
|
X when X < 16#d800; X > 16#dfff, X < 16#fffe ->
|
||||||
|
string(Rest, Stack, Callbacks, Opts, [X] ++ String)
|
||||||
|
; _ ->
|
||||||
|
string(Rest, Stack, Callbacks, Opts, [D, C, B, A, $u, ?rsolidus] ++ String)
|
||||||
|
end;
|
||||||
escaped_unicode(<<D, Rest/binary>>, Stack, Callbacks, Opts, String, [C, B, A]) when ?is_hex(D) ->
|
escaped_unicode(<<D, Rest/binary>>, Stack, Callbacks, Opts, String, [C, B, A]) when ?is_hex(D) ->
|
||||||
string(Rest, Stack, Callbacks, Opts, [D, C, B, A, $u, ?rsolidus] ++ String);
|
string(Rest, Stack, Callbacks, Opts, [D, C, B, A, $u, ?rsolidus] ++ String);
|
||||||
escaped_unicode(<<S, Rest/binary>>, Stack, Callbacks, Opts, String, Acc) when ?is_hex(S) ->
|
escaped_unicode(<<S, Rest/binary>>, Stack, Callbacks, Opts, String, Acc) when ?is_hex(S) ->
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue