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

myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lists...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
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
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New

Other popular topics Top

johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 52673 488
New
jaysoifer
Is there a way to rollback a specific migration and only that one (“skipping” all the other ones)? Would mix ecto.rollback -v 200809061...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 43487 311
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New

Latest on Elixir Forum

We're in Beta

About us Mission Statement