-
-
Notifications
You must be signed in to change notification settings - Fork 388
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
leave more characters unescaped for segments #75
Conversation
treat `;,:@&=+$-_.!~*()` characters as safe to be part of segment
@Guria So what's the core issue here? It was a lot of text, but the expectation is that escaping is looser (to make it prettier with the colon)? I have no strong opinions, but I'd like to get another set of eyes on it first. |
@blakeembrey core issue was here: https://tonicdev.com/guria/5715e701d286771100079fb2 |
Of course, no hurry here. We have a recommendation on how to deal with it to avoid Also I was think about keep current escaping behaviour and introduce less strict as option. That's way it could be introduced without any harm to existing users. |
I personally think that readability in urls is a good thing - even if it just creates joy amongst developers :) Don't really see why it should break matching though? |
@maxfrigge Any change to a public facing API is a breaking change, someone may be relying on (however unlikely) the fact that @Guria You could also manage stringify yourself, for now - it's pretty simple to do and the current code doing it was very trivial to implement - just loop over the parsed string and concat together throwing errors on invalid data. |
@dougwilson Any thoughts from you here? I'm not particularly keen on merging, it feels like a simple application left to user-land for now. That said, it is a very trivial fix and the only possible bugs I can think it may introduce on users is if they are parsing generated URLs (it'd be possible to confuse the URL parser if it was previously a relative URL segment at the beginning by putting a colon in the segment). |
Ohh, thanks for pointing that out. Seems I really can use own So no we have several options here:
I can start from 3rd option now, but will leave a pr open in case you will decide that this fix might be useful for other users too. |
@blakeembrey so I have seen various people (online and in person) who do not like the That said, I would suggest keeping the current safe behavior, but do not see a reason why adding an option for this new behavior would be bad (since it's optional, and more importantly, opt-in). I would leave the ultimate decision to you, but that is my opinion :) |
treat `;,:@&=+$-_.!~*()` characters as safe to be part of segment
Merged as an option. Use |
URLON updated to 3.0.1, which introduces improved readability by loose escaping, better safety by fixing undefined and compatibility with utm tracking links. See https://github.com/cerebral/urlon/releases/tag/3.0.0 for details. path-to-regex update allows avoid unnecessary of colons used to preserve types. See pillarjs/path-to-regexp#75 for details. `null` values is now supprted in path parts. BREAKING CHANGE: Stringify format changed. Parsing values generated by previous version isn't possible anymore. fixes #27, fixes #28
URLON updated to 3.0.1, which introduces improved readability by loose escaping, better safety by fixing undefined and compatibility with utm tracking links. See https://github.com/cerebral/urlon/releases/tag/3.0.0 for details. path-to-regex update allows avoid unnecessary of colons used to preserve types. See pillarjs/path-to-regexp#75 for details. `null` values is now supprted in path parts. BREAKING CHANGE: Stringify format changed. Parsing values generated by previous version isn't possible anymore. fixes #27, fixes #28
treat `;,:@&=+$-_.!~*()` characters as safe to be part of segment
I am using
path-to-regexp
inurl-mapper
which allows to map almost any json compatible object to url with path and query. The key feature is preserving type of values, soassert.equal(parse(stringify(object)), object)
.Routes defined with
path-to-regexp
format, keys of object defined in route stringified withpath-to-regexp
, rest of keys goes to query part with help of urlon.Tonic demo.
url-mapper
allows map only simple values (strings, numbers and booleans) to path parameters. To allow preserving type for numbers and booleans they are prepended with colon character. Here is where issue starts:path-to-regexp
encodes segments withencodeURIComponent
function and converts colons to '%3A', which makes url to look more cryptic in path part.Tonic demo
This PR tries to address this problem by treat
;,:@&=+$-_.!~*()
characters as safe to be part of segment. According to MDN:It means there is no need to use
encodeURIComponent
to encode segment part, because it's too strict. I have introduced extended version onencodeURI
with escaping/?#'"
characters and added some tests as well.I am suppose, that it should be treated as
major
change because it potentially could break matching and expectations.