Reputation: 3910
I have a Phoenix router with the following structure. The issue is that the param "name" can have a forward slash it in depending on the item such as "ABC/D"
This '/' char gets interpreted as a different route though that does not exist. Is there some way to designate that the forward slash is part of the name and not part of a route?
scope "/api", AppWeb do
scope "/pricing" do
resources("/inventory", InventoryController, param: "name") do
get("/quote", InventoryController, :quote, as: :pricing)
end
end
end
Upvotes: 0
Views: 360
Reputation: 121000
This question has very little to do with elixir, that’s HTTP protocol question. To pass any symbol as path/query part in the URL and prevent handlers from treating it as a path and/or controlling symbol, one should url-encode
it.
That said, one should encode forward slashes as %2F
in the path/query parts of URI. The below code shows how it’d be treated by router.
# ⇓⇓
iex|💧|1 ▸ URI.decode("https://google.com/?foo=bar%2Fbaz")
"https://google.com/?foo=bar/baz"
Upvotes: 2