fix(authz): placeholder regular replace
This commit is contained in:
parent
060962700e
commit
d7c7292321
|
@ -68,6 +68,8 @@
|
||||||
|
|
||||||
-define(CONF_KEY_PATH, [authorization, sources]).
|
-define(CONF_KEY_PATH, [authorization, sources]).
|
||||||
|
|
||||||
|
-define(RE_PLACEHOLDER, "\\$\\{[a-z0-9\\-]+\\}").
|
||||||
|
|
||||||
-define(USERNAME_RULES_EXAMPLE, #{username => user1,
|
-define(USERNAME_RULES_EXAMPLE, #{username => user1,
|
||||||
rules => [ #{topic => <<"test/toopic/1">>,
|
rules => [ #{topic => <<"test/toopic/1">>,
|
||||||
permission => <<"allow">>,
|
permission => <<"allow">>,
|
||||||
|
|
|
@ -38,10 +38,10 @@ description() ->
|
||||||
parse_query(undefined) ->
|
parse_query(undefined) ->
|
||||||
undefined;
|
undefined;
|
||||||
parse_query(Sql) ->
|
parse_query(Sql) ->
|
||||||
case re:run(Sql, "'%[ucCad]'", [global, {capture, all, list}]) of
|
case re:run(Sql, ?RE_PLACEHOLDER, [global, {capture, all, list}]) of
|
||||||
{match, Variables} ->
|
{match, Variables} ->
|
||||||
Params = [Var || [Var] <- Variables],
|
Params = [Var || [Var] <- Variables],
|
||||||
{re:replace(Sql, "'%[ucCad]'", "?", [global, {return, list}]), Params};
|
{re:replace(Sql, ?RE_PLACEHOLDER, "?", [global, {return, list}]), Params};
|
||||||
nomatch ->
|
nomatch ->
|
||||||
{Sql, []}
|
{Sql, []}
|
||||||
end.
|
end.
|
||||||
|
|
|
@ -38,7 +38,7 @@ description() ->
|
||||||
parse_query(undefined) ->
|
parse_query(undefined) ->
|
||||||
undefined;
|
undefined;
|
||||||
parse_query(Sql) ->
|
parse_query(Sql) ->
|
||||||
case re:run(Sql, "'%[ucCad]'", [global, {capture, all, list}]) of
|
case re:run(Sql, ?RE_PLACEHOLDER, [global, {capture, all, list}]) of
|
||||||
{match, Variables} ->
|
{match, Variables} ->
|
||||||
Params = [Var || [Var] <- Variables],
|
Params = [Var || [Var] <- Variables],
|
||||||
Vars = ["$" ++ integer_to_list(I) || I <- lists:seq(1, length(Params))],
|
Vars = ["$" ++ integer_to_list(I) || I <- lists:seq(1, length(Params))],
|
||||||
|
|
Loading…
Reference in New Issue