Merge pull request #12986 from thalesmg/fix-mv-name-length-r57-20240507
fix(message validation): limit the length of validation name
This commit is contained in:
commit
02c58b67f0
|
@ -18,8 +18,6 @@
|
||||||
api_schema/1
|
api_schema/1
|
||||||
]).
|
]).
|
||||||
|
|
||||||
-export([validate_name/1]).
|
|
||||||
|
|
||||||
%%------------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
%% Type declarations
|
%% Type declarations
|
||||||
%%------------------------------------------------------------------------------
|
%%------------------------------------------------------------------------------
|
||||||
|
@ -55,7 +53,7 @@ fields(validation) ->
|
||||||
binary(),
|
binary(),
|
||||||
#{
|
#{
|
||||||
required => true,
|
required => true,
|
||||||
validator => fun validate_name/1,
|
validator => fun emqx_resource:validate_name/1,
|
||||||
desc => ?DESC("name")
|
desc => ?DESC("name")
|
||||||
}
|
}
|
||||||
)},
|
)},
|
||||||
|
@ -200,16 +198,6 @@ ensure_array(undefined, _) -> undefined;
|
||||||
ensure_array(L, _) when is_list(L) -> L;
|
ensure_array(L, _) when is_list(L) -> L;
|
||||||
ensure_array(B, _) -> [B].
|
ensure_array(B, _) -> [B].
|
||||||
|
|
||||||
validate_name(Name) ->
|
|
||||||
%% see `MAP_KEY_RE' in hocon_tconf
|
|
||||||
RE = <<"^[A-Za-z0-9]+[A-Za-z0-9-_]*$">>,
|
|
||||||
case re:run(Name, RE, [{capture, none}]) of
|
|
||||||
match ->
|
|
||||||
ok;
|
|
||||||
nomatch ->
|
|
||||||
{error, <<"must conform to regex: ", RE/binary>>}
|
|
||||||
end.
|
|
||||||
|
|
||||||
validate_sql(SQL) ->
|
validate_sql(SQL) ->
|
||||||
case emqx_message_validation:parse_sql_check(SQL) of
|
case emqx_message_validation:parse_sql_check(SQL) of
|
||||||
{ok, _Parsed} ->
|
{ok, _Parsed} ->
|
||||||
|
|
|
@ -195,7 +195,6 @@ invalid_names_test_() ->
|
||||||
?_assertThrow(
|
?_assertThrow(
|
||||||
{_Schema, [
|
{_Schema, [
|
||||||
#{
|
#{
|
||||||
reason := <<"must conform to regex:", _/binary>>,
|
|
||||||
kind := validation_error,
|
kind := validation_error,
|
||||||
path := "message_validation.validations.1.name"
|
path := "message_validation.validations.1.name"
|
||||||
}
|
}
|
||||||
|
@ -209,7 +208,9 @@ invalid_names_test_() ->
|
||||||
<<"name!">>,
|
<<"name!">>,
|
||||||
<<"some name">>,
|
<<"some name">>,
|
||||||
<<"nãme"/utf8>>,
|
<<"nãme"/utf8>>,
|
||||||
<<"test_哈哈"/utf8>>
|
<<"test_哈哈"/utf8>>,
|
||||||
|
%% long name
|
||||||
|
binary:copy(<<"a">>, 256)
|
||||||
]
|
]
|
||||||
].
|
].
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue