From 63043e0751b6f8e7838ade44dd0c3e6d781d0adf Mon Sep 17 00:00:00 2001 From: Troels Thomsen Date: Tue, 25 Feb 2025 16:50:06 +0100 Subject: [PATCH 1/2] Verify that path can contain colon --- test/bypass_test.exs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/bypass_test.exs b/test/bypass_test.exs index 8c26cc8..71ec7d0 100644 --- a/test/bypass_test.exs +++ b/test/bypass_test.exs @@ -643,4 +643,15 @@ defmodule BypassTest do Bypass.open(:error) end end + + test "path can contain colon" do + bypass = Bypass.open() + + Bypass.expect(bypass, "POST", "/resources/:resource", fn conn -> + assert conn.params == %{ "resource" => ":resource" } + Plug.Conn.send_resp(conn, 200, "") + end) + + assert {:ok, 200, ""} = request(bypass.port, "/resources/:resource") + end end From d2763e77a30ccc73f2245fd9fefa90f9e1571b68 Mon Sep 17 00:00:00 2001 From: Troels Thomsen Date: Tue, 25 Feb 2025 16:52:04 +0100 Subject: [PATCH 2/2] Avoid interpreting path as route --- lib/bypass/instance.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/bypass/instance.ex b/lib/bypass/instance.ex index f8ae2b1..74bfe2e 100644 --- a/lib/bypass/instance.ex +++ b/lib/bypass/instance.ex @@ -4,7 +4,7 @@ defmodule Bypass.Instance do use GenServer, restart: :transient import Bypass.Utils - import Plug.Router.Utils, only: [build_path_match: 1] + import Plug.Router.Utils, only: [build_path_match: 1, split: 1] def start_link(opts \\ []) do GenServer.start_link(__MODULE__, [opts]) @@ -297,7 +297,7 @@ defmodule Bypass.Instance do end defp route_info(method, path, %{expectations: expectations} = _state) do - segments = build_path_match(path) |> elem(1) + segments = path |> split route = expectations