Просмотр исходного кода

fix(rule): replace sql crlf with spaces

get around the hocon bug: error handling escape character \n
EMQ-YangM 3 лет назад
Родитель
Сommit
6cff53ad67
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
 %% 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) ->
 '/rule_events'(get, _Params) ->
     {200, emqx_rule_events:event_info()}.
     {200, emqx_rule_events:event_info()}.
 
 
@@ -201,7 +206,7 @@ param_path_id() ->
         <<>> ->
         <<>> ->
             {400, #{code => 'BAD_REQUEST', message => <<"empty rule id is not allowed">>}};
             {400, #{code => 'BAD_REQUEST', message => <<"empty rule id is not allowed">>}};
         Id ->
         Id ->
-            Params = filter_out_request_body(Params0),
+            Params = filter_out_request_body(replace_sql_clrf(Params0)),
             ConfPath = emqx_rule_engine:config_key_path() ++ [Id],
             ConfPath = emqx_rule_engine:config_key_path() ++ [Id],
             case emqx_rule_engine:get_rule(Id) of
             case emqx_rule_engine:get_rule(Id) of
                 {ok, _Rule} ->
                 {ok, _Rule} ->