Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

One big question in URL design is this:

Do path parameters get to have / in their values?

Let’s say you have a link shortener service and want to allow users to define shortcuts like /mypath/:rest where rest is appended to example.com/

Now you’re in a very interesting position when it comes to resolving URLs.

Curious to hear folks with experience in this



As per RFC 3986 [1], reserved characters such as , and / must be URL encoded.

, is encoded as %2C

/ is encoded as %2F

[1] https://www.rfc-editor.org/rfc/rfc3986


That's not the question. The question is what if you have an open ended URL param that can also have subpaths?


This can be a complex topic if you don’t set clear constraints on what constitutes a valid character in your URL or domain.

For instance, in query parameters, spaces are encoded as '+'. But what if '+' is also a valid character in your domain? You then need to disambiguate i.e between "name?foo+bar" meaning "foo bar" or "foo+bar". Which one is the user actually referring to?

In our case, we ended up needing users to send the name in the body, and now we have to manage multiple encoding protocols (url, queryparam, the body...).


Wouldn't you just encode the "+" if you wanted it as a literal?


A better example is the name: "foo%20bar".

A user might have entities named "foo bar", "foo%20bar", and "foo%2520bar". Sometimes, mistakes happened because users forgot to double encode or they used the wrong protocol. As this names were used in URL, query parameters, and the body, and each has its own.

As I mentioned, with clear constraints and rules, we can accomplish anything we need, it can get complex. My takeaway from this project is to limit the valid characters and make it simple for everyone.


Actually, not encoded slashes in the paths are not that unheard of as one might think. As an example, this is actual Wikipedia article about... the meaning of "two slashes": https://en.wikipedia.org/wiki/// . Also, encountering buggy concatenations like example.com//some-path or example.com/base//some-path is quite common.

Don't ask how I know.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: