Skip to content

Commit

Permalink
fix(api-clients): escape the searching string
Browse files Browse the repository at this point in the history
  • Loading branch information
HJianBo committed Oct 25, 2021
1 parent fd34eb1 commit 99453df
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion apps/emqx_management/src/emqx_mgmt_api_clients.erl
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ query({Qs, Fuzzy}, Start, Limit) ->
match_fun(Ms, Fuzzy) ->
MsC = ets:match_spec_compile(Ms),
REFuzzy = lists:map(fun({K, like, S}) ->
{ok, RE} = re:compile(S),
{ok, RE} = re:compile(escape(S)),
{K, like, RE}
end, Fuzzy),
fun(Rows) ->
Expand All @@ -347,6 +347,9 @@ match_fun(Ms, Fuzzy) ->
end
end.

escape(B) when is_binary(B) ->
re:replace(B, <<"\\\\">>, <<"\\\\\\\\">>, [{return, binary}, global]).

run_fuzzy_match(_, []) ->
true;
run_fuzzy_match(E = {_, #{clientinfo := ClientInfo}, _}, [{Key, _, RE}|Fuzzy]) ->
Expand Down Expand Up @@ -450,4 +453,9 @@ params2qs_test() ->

[{{'$1', #{}, '_'}, [], ['$_']}] = qs2ms([]).

escape_test() ->
Str = <<"\\n">>,
{ok, Re} = re:compile(escape(Str)),
{match, _} = re:run(<<"\\name">>, Re).

-endif.

0 comments on commit 99453df

Please sign in to comment.