6 ms·
This is great stuff. The reserved characters are different for each part But if it's true that you can _optionally_ percent-encode any character in any part o
by jrochkind1 13y ago
This is great stuff.
The reserved characters are different for each part
But if it's true that you can _optionally_ percent-encode any character in any part of the URL (path or query) -- is this true? I think so -- then there is in fact a way to _encode_ any URI without as much syntactical awareness of the URI structure.
This means that the "blue+light blue" string has to be encoded differently in the path and query parts: "http://example.com/blue+light%20blue?blue%2Blight+blue" http://example.com/blue+light%20blue?blue%2Blight+blue". From there you can deduce that encoding a fully constructed URL is impossible without a syntactical awareness of the URL structure.
Does it? Could you optionally encode it as:
http://example.com/blue%2Blight%20blue?blue%2Blight%20blue
That is, percent encode (not the legacy encode-space-as-plus) both the plus and the space in both path and query?
* You'd still need enough syntactic awareness of the URI structure to know to leave path-seperator "/" alone, and query-part-beginning "?" alone.
* And you'd need even more syntactic awareness to properly _decode_ URIs, which may not have chosen to optionally always-percent-encode.
* But it might be wise if libraries chose to encode things in that consistent way, for instance encoding plus in path even though it's not required, never encoding space as plus even in query.
* I think there is _no_ good reason for any modern library to encode spaces, even in the query string, as "+" instead of %20. Even though many of them do. Don't do it.
* I don't use Java much, and couldn't entirely follow those examples (this stuff is confusing to talk about -- as in all escaping issues) -- but it sure does seem like those parts of stdlib/commonly used libraries are pretty darn broken. (And I'm sure Java is not alone here -- there is a long history of devs being confused about this stuff. Again, as with just about any escaping-related issue).
- stan_rogers 13y agoThe + as a space in a URL often originates from form data submitted via GET (the wisdom of which is a separate topic for discussion). At least we've gotten to the point now where we've pretty much dispensed with nested hierarchies of framesets, in which the "percent" encoding needed to be done multiple times to different parts of the URL so each target could decode its source and dispatch an appropriately-encoded source to its descendants, yielding %25252520 and other similar monstrosities.
- deleted 13y ago[deleted]
- gpvos 13y agoAre you using some kind of framework? I don't think there is a way in plain HTTP+HTML to pass URLs to child frames in a frameset.
- Hello71 13y agoThere's target=frame (never used in practice), but that's only one level down.
- stan_rogers 13y agoYou can use an encoded target=frame to pass it down as many levels as you want (encode the ampersand and the equals sign, and of course the percent sign for things that arent at the immediate child level). The '90s sucked for web dev, but there was almost always a (scary and hackish) way.
- gpvos 13y agoBut which mechanism would do the substitution of those parameters in the HTML of the child frame? I still fail to see how it would be done without either Javascript or server-side code. (And I did web dev in the 90s, with frames, but apparently was not evil enough to think of such stuff.)
- Udo 13y agoI wanted to make the same comment after reading the article. You're correct. The "+" literal in the URL is a painful remnant and at least when encoding I think it should be avoided entirely - so I think the article has it wrong when they say the string has to be encoded differently depending on its place within the URL. However, it's something to be aware of when decoding.
- gpvos 13y agoThe only problem I can think of is that the URL becomes a bit longer than necessary, so you might hit IE's URL length limit a bit earlier.