Merge pull request #13131 from zmstone/0527-handle-unicode-in-template-strings

0527 handle unicode in template strings
This commit is contained in:
zmstone 2024-05-30 15:37:43 +02:00 committed by GitHub
commit 460081a22e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 30 additions and 16 deletions

View File

@ -2,7 +2,7 @@
{application, emqx, [
{id, "emqx"},
{description, "EMQX Core"},
{vsn, "5.4.0"},
{vsn, "5.3.1"},
{modules, []},
{registered, []},
{applications, [

View File

@ -2471,7 +2471,7 @@ converter_ciphers(Ciphers, _Opts) when is_binary(Ciphers) ->
default_ciphers(Which) ->
lists:map(
fun erlang:iolist_to_binary/1,
fun unicode:characters_to_binary/1,
do_default_ciphers(Which)
).
@ -2494,7 +2494,7 @@ bin_str_converter(I, _) when is_integer(I) ->
integer_to_binary(I);
bin_str_converter(X, _) ->
try
iolist_to_binary(X)
unicode:characters_to_binary(X)
catch
_:_ ->
throw("must_quote")
@ -2649,7 +2649,7 @@ to_comma_separated_list(Str) ->
{ok, string:tokens(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) ->
{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
{ok, URIMap} ->
URIString = emqx_http_lib:normalize(URIMap),
{ok, iolist_to_binary(URIString)};
{ok, unicode:characters_to_binary(URIString)};
Error ->
Error
end.
@ -2666,13 +2666,13 @@ to_url(Str) ->
to_json_binary(Str) ->
case emqx_utils_json:safe_decode(Str) of
{ok, _} ->
{ok, iolist_to_binary(Str)};
{ok, unicode:characters_to_binary(Str)};
Error ->
Error
end.
to_template(Str) ->
{ok, iolist_to_binary(Str)}.
{ok, unicode:characters_to_binary(Str, utf8)}.
to_template_str(Str) ->
{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}}.
validate_tcp_keepalive(Value) ->
case iolist_to_binary(Value) of
case unicode:characters_to_binary(Value) of
<<"none">> ->
ok;
_ ->
@ -2949,7 +2949,7 @@ convert_servers(undefined) ->
convert_servers(Map) when is_map(Map) ->
try
List = convert_hocon_map_host_port(Map),
iolist_to_binary(string:join(List, ","))
unicode:characters_to_binary(string:join(List, ","))
catch
_:_ ->
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) ->
%% if the old config was a string array
%% 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) ->
normalize_host_port_str(Str).
%% remove spaces around comma (,)
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.
%% NOTE: Validator is called after converter.
@ -3442,8 +3442,10 @@ ensure_default_listener(Map, ListenerType) ->
NewMap = Map#{<<"default">> => default_listener(ListenerType)},
keep_default_tombstone(NewMap, #{}).
cert_file(_File, client) -> undefined;
cert_file(File, server) -> iolist_to_binary(filename:join(["${EMQX_ETC_DIR}", "certs", File])).
cert_file(_File, client) ->
undefined;
cert_file(File, server) ->
unicode:characters_to_binary(filename:join(["${EMQX_ETC_DIR}", "certs", File])).
mqtt_converter(#{<<"keepalive_multiplier">> := Multi} = Mqtt, _Opts) ->
case round(Multi * 100) =:= round(?DEFAULT_MULTIPLIER * 100) of

View File

@ -930,3 +930,15 @@ timeout_types_test_() ->
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),
?assertEqual(
#{<<"root">> => #{<<"template">> => <<"中文"/utf8>>}},
hocon_tconf:check_plain(Sc, Hocon)
).

View File

@ -1,7 +1,7 @@
%% -*- mode: erlang -*-
{application, emqx_auth, [
{description, "EMQX Authentication and authorization"},
{vsn, "0.4.0"},
{vsn, "0.3.1"},
{modules, []},
{registered, [emqx_auth_sup]},
{applications, [

View File

@ -1,7 +1,7 @@
%% -*- mode: erlang -*-
{application, emqx_bridge_kafka, [
{description, "EMQX Enterprise Kafka Bridge"},
{vsn, "0.3.0"},
{vsn, "0.3.1"},
{registered, [emqx_bridge_kafka_consumer_sup]},
{applications, [
kernel,

View File

@ -2,7 +2,7 @@
{application, emqx_management, [
{description, "EMQX Management API and CLI"},
% strict semver, bump manually!
{vsn, "5.3.0"},
{vsn, "5.2.1"},
{modules, []},
{registered, [emqx_management_sup]},
{applications, [