Skip to content

Commit

Permalink
Remove fragment part from query on redirects (#2728)
Browse files Browse the repository at this point in the history
  • Loading branch information
sokolnickim authored Sep 19, 2023
1 parent 370f435 commit 87dc84f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/phoenix_live_view/channel.ex
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ defmodule Phoenix.LiveView.Channel do
end

defp patch_params_and_action!(socket, %{to: to}) do
destructure [path, query], :binary.split(to, "?")
destructure [path, query], :binary.split(to, ["?", "#"], [:global])
to = %{socket.host_uri | path: path, query: query}

case Route.live_link_info!(socket, socket.private.root_view, to) do
Expand Down
7 changes: 7 additions & 0 deletions test/phoenix_live_view/integrations/params_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,13 @@ defmodule Phoenix.LiveView.ParamsTest do
assert_receive {:handle_params, "http://www.example.com/counter/123?from=rehandled_params",
%{val: 1}, %{"from" => "rehandled_params", "id" => "123"}}
end

test "remove fragment from query", %{conn: conn} do
{:ok, counter_live, _html} = live(conn, "/counter/123")

send(counter_live.pid, {:push_patch, "/counter/123?query=value#fragment"})
assert render(counter_live) =~ rendered_to_string(~s|%{"id" => "123", "query" => "value"}|)
end
end

describe "push_navigate" do
Expand Down

0 comments on commit 87dc84f

Please sign in to comment.