pejrich

pejrich

VerifiedRoutes is encoding `+` in url path

I have some code like this:

defmodule Unicode do
  @derive Phoenix.Param
  defstruct [id: "U+0041"]
  def dummy, do: %__MODULE__{}
end

<.link href={~p"/path/#{Unicode.dummy()}"}>some link</.link>

The issue is that VerifiedRoutes(it’s not Phoenix.Param as it stops if I remove the ~p) is encoding the interpolated portion to U%2B0041. The issue is that since a + is valid in the path component of a URL, the browser doesn’t decode it, so the URL in the address bar shows the encoded version of the URL which is not exactly pretty. The route still works, but it just looks a bit ugly.

Is this a bug or am I missing something here with URL encoding? I notice that URI will correctly decode the route, and also if I try to encode it again with URI is seems to keep it as U+0041, which seems to support that the + is allowed there. Does anyone know if there’s a reason this gets encoded by VerifiedRoutes? For now i’m just leaving the ~p off.

Also interestingly it seems to only do it if it’s interpolated. If I plug a string directly into the ~p it keeps the + as a +. When I interpolate it, it gets encoded.

Most Liked

LostKobrakai

LostKobrakai

This might be to disambiguate the uri percent encoding where + may or may not be percent encoded vs. the application/x-www-form-urlencoded encoding where a literal + is an alternative encoding for a space and equivalent to %20.

Where Next?

Popular in Questions Top

vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New

Other popular topics Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

We're in Beta

About us Mission Statement