Explorar el Código

Merge pull request #13687 from zmstone/0823-fix-http-action-url-query-string-concatenation

fix(bridge/http): do not insert a '/' before '?' (query string)
zmstone hace 1 año
padre
commit
5b6f5b0d6e
Se han modificado 1 ficheros con 17 adiciones y 2 borrados
  1. 17 2
      apps/emqx_bridge_http/src/emqx_bridge_http_connector.erl

+ 17 - 2
apps/emqx_bridge_http/src/emqx_bridge_http_connector.erl

@@ -851,7 +851,19 @@ formalize_request(_Method, BasePath, {Path, Headers}) ->
 %%
 %% See also: `join_paths_test_/0`
 join_paths(Path1, Path2) ->
-    [without_trailing_slash(Path1), $/, without_starting_slash(Path2)].
+    case is_start_with_question_mark(Path2) of
+        true ->
+            [Path1, Path2];
+        false ->
+            [without_trailing_slash(Path1), $/, without_starting_slash(Path2)]
+    end.
+
+is_start_with_question_mark([$? | _]) ->
+    true;
+is_start_with_question_mark(<<$?, _/binary>>) ->
+    true;
+is_start_with_question_mark(_) ->
+    false.
 
 without_starting_slash(Path) ->
     case do_without_starting_slash(Path) of
@@ -1080,7 +1092,10 @@ join_paths_test_() ->
         ?_assert(iolists_equal("/cde", join_paths("/", "cde"))),
         ?_assert(iolists_equal("/cde", join_paths("/", "/cde"))),
         ?_assert(iolists_equal("//cde/", join_paths("/", "//cde/"))),
-        ?_assert(iolists_equal("abc///cde/", join_paths("abc//", "//cde/")))
+        ?_assert(iolists_equal("abc///cde/", join_paths("abc//", "//cde/"))),
+        ?_assert(iolists_equal("abc?v=1", join_paths("abc", "?v=1"))),
+        ?_assert(iolists_equal("abc?v=1", join_paths("abc", <<"?v=1">>))),
+        ?_assert(iolists_equal("abc/?v=1", join_paths("abc/", <<"?v=1">>)))
     ].
 
 -endif.