How to handle URLs with a ":" (colon) in them

Hi there. I’m currently working on mirroring the NPM registry and they have a route that looks like this:


I tried creating a routes like these:

put  "/registry/-/user/org.couchdb.user\::user", RegistryLoginController, :edit
put  "/registry/-/user/org.couchdb.user\\::user", RegistryLoginController, :edit
put  "/registry/-/user/org.couchdb.user%3A:user", RegistryLoginController, :edit

But to no avail. Is there a way to escape a : character in a route to not act as a variable?

What about

put  "/registry/-/user/:user", RegistryLoginController, :edit

and then parse out

%{"user" => "org.couchdb.user:" <> user}

from the params?


That’s a known issue. Just parse the path yourself…

Thanks! This is what I ended up doing, but didn’t feel right and wanted to make sure I wasn’t missing something obvious.

Wasn’t aware. This is my first time using Phoenix coming from Rails.

Yeah, and this is kind of a strange limitation in phoenix router. I’ve suffered from it in several projects too

it’s probably a very good “first issue” to submit PR for Phoenix to be fixed

I would have thought “:” was reserved for the port number?

It has a few valid meanings, like

now is that tcp or http that says that cause I get it in the context of a db for example.

HTTP, afaik. Not that it’s a good idea or anything, but it’s a supported thing. Without putting much time into searching this SO has some info.

1 Like