Pārlūkot izejas kodu

fix(authz): placeholder regular replace

JimMoen 4 gadi atpakaļ
vecāks
revīzija
d7c7292321

+ 2 - 0
apps/emqx_authz/include/emqx_authz.hrl

@@ -68,6 +68,8 @@
 
 -define(CONF_KEY_PATH, [authorization, sources]).
 
+-define(RE_PLACEHOLDER, "\\$\\{[a-z0-9\\-]+\\}").
+
 -define(USERNAME_RULES_EXAMPLE, #{username => user1,
                                   rules => [ #{topic => <<"test/toopic/1">>,
                                                permission => <<"allow">>,

+ 2 - 2
apps/emqx_authz/src/emqx_authz_mysql.erl

@@ -38,10 +38,10 @@ description() ->
 parse_query(undefined) ->
     undefined;
 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} ->
             Params = [Var || [Var] <- Variables],
-            {re:replace(Sql, "'%[ucCad]'", "?", [global, {return, list}]), Params};
+            {re:replace(Sql, ?RE_PLACEHOLDER, "?", [global, {return, list}]), Params};
         nomatch ->
             {Sql, []}
     end.

+ 1 - 1
apps/emqx_authz/src/emqx_authz_postgresql.erl

@@ -38,7 +38,7 @@ description() ->
 parse_query(undefined) ->
     undefined;
 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} ->
             Params = [Var || [Var] <- Variables],
             Vars = ["$" ++ integer_to_list(I) || I <- lists:seq(1, length(Params))],