Skip to content

Commit

Permalink
Encode site domain when redirecting a shared link
Browse files Browse the repository at this point in the history
  • Loading branch information
ukutaht authored and oliver-kriska committed Dec 23, 2020
1 parent e338f58 commit 55e4e59
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/plausible_web/controllers/stats_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ defmodule PlausibleWeb.StatsController do
|> put_session(shared_link_key, %{
valid_until: Timex.now() |> Timex.shift(hours: 1) |> DateTime.to_unix()
})
|> redirect(to: "/#{shared_link.site.domain}")
|> redirect(to: "/#{URI.encode_www_form(shared_link.site.domain)}")
end

defp remove_email_report_banner(conn, site) do
Expand Down
8 changes: 8 additions & 0 deletions test/plausible_web/controllers/stats_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ defmodule PlausibleWeb.StatsControllerTest do
conn = get(conn, "/#{site.domain}")
assert html_response(conn, 200) =~ "stats-react-container"
end

test "encodes URI when redirecting", %{conn: conn} do
site = insert(:site, domain: "test-site.com/wat")
link = insert(:shared_link, site: site)

conn = get(conn, "/share/#{link.slug}")
assert redirected_to(conn, 302) == "/test-site.com%2Fwat"
end
end

describe "POST /share/:slug/authenticate" do
Expand Down

0 comments on commit 55e4e59

Please sign in to comment.