ソースを参照

Merge pull request #7355 from EMQ-YangM/upstream_master

fix(rule): replace sql crlf with spaces
Yang Miao 3 年 前
コミット
79b8c63b54
1 ファイル変更6 行追加1 行削除
  1. 6 1
      apps/emqx_rule_engine/src/emqx_rule_engine_api.erl

+ 6 - 1
apps/emqx_rule_engine/src/emqx_rule_engine_api.erl

@@ -189,6 +189,11 @@ param_path_id() ->
 %% Rules API
 %%------------------------------------------------------------------------------
 
+%% To get around the hocon bug, we replace crlf with spaces
+replace_sql_clrf(#{ <<"sql">> := SQL } = Params) ->
+    NewSQL = re:replace(SQL, "[\r\n]", " ", [{return, binary}, global]),
+    Params#{<<"sql">> => NewSQL}.
+
 '/rule_events'(get, _Params) ->
     {200, emqx_rule_events:event_info()}.
 
@@ -201,7 +206,7 @@ param_path_id() ->
         <<>> ->
             {400, #{code => 'BAD_REQUEST', message => <<"empty rule id is not allowed">>}};
         Id ->
-            Params = filter_out_request_body(Params0),
+            Params = filter_out_request_body(replace_sql_clrf(Params0)),
             ConfPath = emqx_rule_engine:config_key_path() ++ [Id],
             case emqx_rule_engine:get_rule(Id) of
                 {ok, _Rule} ->