Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions lib/phoenix/verified_routes.ex
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ defmodule Phoenix.VerifiedRoutes do
end

defp inject_path(
{%__MODULE__{} = route, static?, _endpoint_ctx, _route_ast, path_ast, static_ast},
{%__MODULE__{} = route, static?, _endpoint_ctx, path_ast, static_ast, _static_url_ast},
env
) do
if static? do
Expand All @@ -393,13 +393,11 @@ defmodule Phoenix.VerifiedRoutes do
end

defp inject_url(
{%__MODULE__{} = route, static?, endpoint_ctx, route_ast, path_ast, _static_ast},
{%__MODULE__{} = route, static?, endpoint_ctx, path_ast, _static_ast, static_url_ast},
env
) do
if static? do
quote do
unquote(__MODULE__).static_url(unquote_splicing([endpoint_ctx, route_ast]))
end
static_url_ast
else
Module.put_attribute(env.module, :phoenix_verified_routes, route)

Expand Down Expand Up @@ -974,7 +972,7 @@ defmodule Phoenix.VerifiedRoutes do
"""
end

{static?, meta, test_path, path_ast, static_ast} =
{static?, meta, test_path, path_ast, static_ast, static_url_ast} =
rewrite_path(route_ast, endpoint_ctx, router, config)

route = %__MODULE__{
Expand All @@ -984,7 +982,7 @@ defmodule Phoenix.VerifiedRoutes do
test_path: test_path
}

{route, static?, endpoint_ctx, route_ast, path_ast, static_ast}
{route, static?, endpoint_ctx, path_ast, static_ast, static_url_ast}
end

defp warn_location(meta, %{line: line, file: file, function: function, module: module}) do
Expand Down Expand Up @@ -1037,7 +1035,12 @@ defmodule Phoenix.VerifiedRoutes do
unquote(__MODULE__).static_path(unquote_splicing([endpoint, rewrite_route]))
end

{static?, meta, test_path, path_ast, static_ast}
static_url_ast =
quote generated: true do
unquote(__MODULE__).static_url(unquote_splicing([endpoint, rewrite_route]))
end

{static?, meta, test_path, path_ast, static_ast, static_url_ast}
end

defp materialize_path(path) do
Expand Down
11 changes: 11 additions & 0 deletions test/phoenix/verified_routes_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,17 @@ defmodule Phoenix.VerifiedRoutesTest do
assert path(socket_with_endpoint(), ~p"/images/foo.png") == "/images/foo.png"
end

test "static urls encode interpolated values like paths" do
name = "a/b?x=1#"

assert ~p"/images/#{name}" == "/images/a%2Fb%3Fx%3D1%23"
assert path(Endpoint, ~p"/images/#{name}") == "/images/a%2Fb%3Fx%3D1%23"
assert url(~p"/images/#{name}") == "https://static.example.com/images/a%2Fb%3Fx%3D1%23"

assert url(Endpoint, ~p"/images/#{name}") ==
"https://static.example.com/images/a%2Fb%3Fx%3D1%23"
end

test "~p dict query strings" do
assert ~p"/posts/5?#{[id: 3]}" == "/posts/5?id=3"
assert ~p"/posts/5?#{[foo: "bar"]}" == "/posts/5?foo=bar"
Expand Down