fix: handle unicode in data integration template strings
The bug was introduced in 5.7.0 (#12893)
This commit is contained in:
parent
c54d25de98
commit
1db9d54d17
|
@ -2471,7 +2471,7 @@ converter_ciphers(Ciphers, _Opts) when is_binary(Ciphers) ->
|
||||||
|
|
||||||
default_ciphers(Which) ->
|
default_ciphers(Which) ->
|
||||||
lists:map(
|
lists:map(
|
||||||
fun erlang:iolist_to_binary/1,
|
fun unicode:characters_to_binary/1,
|
||||||
do_default_ciphers(Which)
|
do_default_ciphers(Which)
|
||||||
).
|
).
|
||||||
|
|
||||||
|
@ -2494,7 +2494,7 @@ bin_str_converter(I, _) when is_integer(I) ->
|
||||||
integer_to_binary(I);
|
integer_to_binary(I);
|
||||||
bin_str_converter(X, _) ->
|
bin_str_converter(X, _) ->
|
||||||
try
|
try
|
||||||
iolist_to_binary(X)
|
unicode:characters_to_binary(X)
|
||||||
catch
|
catch
|
||||||
_:_ ->
|
_:_ ->
|
||||||
throw("must_quote")
|
throw("must_quote")
|
||||||
|
@ -2649,7 +2649,7 @@ to_comma_separated_list(Str) ->
|
||||||
{ok, string:tokens(Str, ", ")}.
|
{ok, string:tokens(Str, ", ")}.
|
||||||
|
|
||||||
to_comma_separated_binary(Str) ->
|
to_comma_separated_binary(Str) ->
|
||||||
{ok, lists:map(fun erlang:list_to_binary/1, string:tokens(Str, ", "))}.
|
{ok, lists:map(fun unicode:characters_to_binary/1, string:tokens(Str, ", "))}.
|
||||||
|
|
||||||
to_comma_separated_atoms(Str) ->
|
to_comma_separated_atoms(Str) ->
|
||||||
{ok, lists:map(fun to_atom/1, string:tokens(Str, ", "))}.
|
{ok, lists:map(fun to_atom/1, string:tokens(Str, ", "))}.
|
||||||
|
@ -2658,7 +2658,7 @@ to_url(Str) ->
|
||||||
case emqx_http_lib:uri_parse(Str) of
|
case emqx_http_lib:uri_parse(Str) of
|
||||||
{ok, URIMap} ->
|
{ok, URIMap} ->
|
||||||
URIString = emqx_http_lib:normalize(URIMap),
|
URIString = emqx_http_lib:normalize(URIMap),
|
||||||
{ok, iolist_to_binary(URIString)};
|
{ok, unicode:characters_to_binary(URIString)};
|
||||||
Error ->
|
Error ->
|
||||||
Error
|
Error
|
||||||
end.
|
end.
|
||||||
|
@ -2666,13 +2666,13 @@ to_url(Str) ->
|
||||||
to_json_binary(Str) ->
|
to_json_binary(Str) ->
|
||||||
case emqx_utils_json:safe_decode(Str) of
|
case emqx_utils_json:safe_decode(Str) of
|
||||||
{ok, _} ->
|
{ok, _} ->
|
||||||
{ok, iolist_to_binary(Str)};
|
{ok, unicode:characters_to_binary(Str)};
|
||||||
Error ->
|
Error ->
|
||||||
Error
|
Error
|
||||||
end.
|
end.
|
||||||
|
|
||||||
to_template(Str) ->
|
to_template(Str) ->
|
||||||
{ok, iolist_to_binary(Str)}.
|
{ok, unicode:characters_to_binary(Str, utf8)}.
|
||||||
|
|
||||||
to_template_str(Str) ->
|
to_template_str(Str) ->
|
||||||
{ok, unicode:characters_to_list(Str, utf8)}.
|
{ok, unicode:characters_to_list(Str, utf8)}.
|
||||||
|
@ -2768,7 +2768,7 @@ validate_keepalive_multiplier(_Multiplier) ->
|
||||||
{error, #{reason => keepalive_multiplier_out_of_range, min => 1, max => 65535}}.
|
{error, #{reason => keepalive_multiplier_out_of_range, min => 1, max => 65535}}.
|
||||||
|
|
||||||
validate_tcp_keepalive(Value) ->
|
validate_tcp_keepalive(Value) ->
|
||||||
case iolist_to_binary(Value) of
|
case unicode:characters_to_binary(Value) of
|
||||||
<<"none">> ->
|
<<"none">> ->
|
||||||
ok;
|
ok;
|
||||||
_ ->
|
_ ->
|
||||||
|
@ -2949,7 +2949,7 @@ convert_servers(undefined) ->
|
||||||
convert_servers(Map) when is_map(Map) ->
|
convert_servers(Map) when is_map(Map) ->
|
||||||
try
|
try
|
||||||
List = convert_hocon_map_host_port(Map),
|
List = convert_hocon_map_host_port(Map),
|
||||||
iolist_to_binary(string:join(List, ","))
|
unicode:characters_to_binary(string:join(List, ","))
|
||||||
catch
|
catch
|
||||||
_:_ ->
|
_:_ ->
|
||||||
throw("bad_host_port")
|
throw("bad_host_port")
|
||||||
|
@ -2957,13 +2957,13 @@ convert_servers(Map) when is_map(Map) ->
|
||||||
convert_servers([H | _] = Array) when is_binary(H) orelse is_list(H) ->
|
convert_servers([H | _] = Array) when is_binary(H) orelse is_list(H) ->
|
||||||
%% if the old config was a string array
|
%% if the old config was a string array
|
||||||
%% we want to make sure it's converted to a comma-separated
|
%% we want to make sure it's converted to a comma-separated
|
||||||
iolist_to_binary([[I, ","] || I <- Array]);
|
unicode:characters_to_binary([[I, ","] || I <- Array]);
|
||||||
convert_servers(Str) ->
|
convert_servers(Str) ->
|
||||||
normalize_host_port_str(Str).
|
normalize_host_port_str(Str).
|
||||||
|
|
||||||
%% remove spaces around comma (,)
|
%% remove spaces around comma (,)
|
||||||
normalize_host_port_str(Str) ->
|
normalize_host_port_str(Str) ->
|
||||||
iolist_to_binary(re:replace(Str, "(\s)*,(\s)*", ",")).
|
unicode:characters_to_binary(re:replace(Str, "(\s)*,(\s)*", ",")).
|
||||||
|
|
||||||
%% @doc Shared validation function for both 'server' and 'servers' string.
|
%% @doc Shared validation function for both 'server' and 'servers' string.
|
||||||
%% NOTE: Validator is called after converter.
|
%% NOTE: Validator is called after converter.
|
||||||
|
@ -3442,8 +3442,10 @@ ensure_default_listener(Map, ListenerType) ->
|
||||||
NewMap = Map#{<<"default">> => default_listener(ListenerType)},
|
NewMap = Map#{<<"default">> => default_listener(ListenerType)},
|
||||||
keep_default_tombstone(NewMap, #{}).
|
keep_default_tombstone(NewMap, #{}).
|
||||||
|
|
||||||
cert_file(_File, client) -> undefined;
|
cert_file(_File, client) ->
|
||||||
cert_file(File, server) -> iolist_to_binary(filename:join(["${EMQX_ETC_DIR}", "certs", File])).
|
undefined;
|
||||||
|
cert_file(File, server) ->
|
||||||
|
unicode:characters_to_binary(filename:join(["${EMQX_ETC_DIR}", "certs", File])).
|
||||||
|
|
||||||
mqtt_converter(#{<<"keepalive_multiplier">> := Multi} = Mqtt, _Opts) ->
|
mqtt_converter(#{<<"keepalive_multiplier">> := Multi} = Mqtt, _Opts) ->
|
||||||
case round(Multi * 100) =:= round(?DEFAULT_MULTIPLIER * 100) of
|
case round(Multi * 100) =:= round(?DEFAULT_MULTIPLIER * 100) of
|
||||||
|
|
|
@ -930,3 +930,13 @@ timeout_types_test_() ->
|
||||||
typerefl:from_string(emqx_schema:timeout_duration_s(), <<"4294967001ms">>)
|
typerefl:from_string(emqx_schema:timeout_duration_s(), <<"4294967001ms">>)
|
||||||
)
|
)
|
||||||
].
|
].
|
||||||
|
|
||||||
|
unicode_template_test() ->
|
||||||
|
Sc = #{
|
||||||
|
roots => [root],
|
||||||
|
fields => #{root => [{template, #{type => emqx_schema:template()}}]}
|
||||||
|
},
|
||||||
|
HoconText = <<"root = {template = \"中文\"}"/utf8>>,
|
||||||
|
{ok, Hocon} = hocon:binary(HoconText),
|
||||||
|
_ = hocon_tconf:check_plain(Sc, Hocon),
|
||||||
|
ok.
|
||||||
|
|
Loading…
Reference in New Issue