fix(api-clients): escape the searching string
This commit is contained in:
parent
fd34eb1f4e
commit
99453df637
|
@ -334,7 +334,7 @@ query({Qs, Fuzzy}, Start, Limit) ->
|
||||||
match_fun(Ms, Fuzzy) ->
|
match_fun(Ms, Fuzzy) ->
|
||||||
MsC = ets:match_spec_compile(Ms),
|
MsC = ets:match_spec_compile(Ms),
|
||||||
REFuzzy = lists:map(fun({K, like, S}) ->
|
REFuzzy = lists:map(fun({K, like, S}) ->
|
||||||
{ok, RE} = re:compile(S),
|
{ok, RE} = re:compile(escape(S)),
|
||||||
{K, like, RE}
|
{K, like, RE}
|
||||||
end, Fuzzy),
|
end, Fuzzy),
|
||||||
fun(Rows) ->
|
fun(Rows) ->
|
||||||
|
@ -347,6 +347,9 @@ match_fun(Ms, Fuzzy) ->
|
||||||
end
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
escape(B) when is_binary(B) ->
|
||||||
|
re:replace(B, <<"\\\\">>, <<"\\\\\\\\">>, [{return, binary}, global]).
|
||||||
|
|
||||||
run_fuzzy_match(_, []) ->
|
run_fuzzy_match(_, []) ->
|
||||||
true;
|
true;
|
||||||
run_fuzzy_match(E = {_, #{clientinfo := ClientInfo}, _}, [{Key, _, RE}|Fuzzy]) ->
|
run_fuzzy_match(E = {_, #{clientinfo := ClientInfo}, _}, [{Key, _, RE}|Fuzzy]) ->
|
||||||
|
@ -450,4 +453,9 @@ params2qs_test() ->
|
||||||
|
|
||||||
[{{'$1', #{}, '_'}, [], ['$_']}] = qs2ms([]).
|
[{{'$1', #{}, '_'}, [], ['$_']}] = qs2ms([]).
|
||||||
|
|
||||||
|
escape_test() ->
|
||||||
|
Str = <<"\\n">>,
|
||||||
|
{ok, Re} = re:compile(escape(Str)),
|
||||||
|
{match, _} = re:run(<<"\\name">>, Re).
|
||||||
|
|
||||||
-endif.
|
-endif.
|
||||||
|
|
Loading…
Reference in New Issue