Board index » delphi » To urlencode or not urlencode

To urlencode or not urlencode


2006-12-28 09:31:51 PM
delphi123
Hi,
Just a quick question regarding urlencoding. Following e.g. this link:
www.codegear.com/default.aspx
If transforming so it looks like this:
www.codegear.com/default.aspx
The server {*word*88}s? (NOTE: Above is just an example
of a website exhibiting a behavior I am curious about.)
AFAIK: I suppose it is partially because the Anchor
fragment '#' should come before the '?' ... But still... Is the
best / most compatible thing simply to drop encoding '#' ?
best regards
Thomas Schulz
 
 

Re:To urlencode or not urlencode

"dk_sz" <XXXX@XXXXX.COM>writes
Quote
Just a quick question regarding urlencoding. Following e.g. this link:
www.codegear.com/default.aspx

If transforming so it looks like this:
www.codegear.com/default.aspx

The server {*word*88}s?
As it should be. The '#' character should not be encoded in this situation.
It is a reserved delimiter that separates the actual URL which is
transmitted to the server from the fragment that the client will use
afterwards.
In this situation, the complete URL is trying to load a page named
"default.aspx", passing it a parameter named "tabid" with a value of "103",
and then telling the browser to jump to an anchor named "Online Stores"
after the page has been loaded. The fragment that follows the '#' is not
transmitted to the web server at all. It is a client-side value that the
server cannot use. By encoding the '#' character, it and the anchor name
become part of the "tabid" value instead, which does get transmitted to the
server, which is wrong.
Quote
AFAIK: I suppose it is partially because the Anchor
fragment '#' should come before the '?' ...
No, it should not. It is in the correct place.
Quote
Is the best / most compatible thing simply to drop encoding '#' ?
Encoding the '#' character in this situation is the wrong thing to do. The
only time it should ever be encoded is when it actually appears inside the
path data or the query string data. If it is used as a delimiter for an
anchor name instead, then DO NOT encode it!
Gambit
 

Re:To urlencode or not urlencode

Quote
Encoding the '#' character in this situation is the wrong thing to do.
The
only time it should ever be encoded is when it actually appears inside the
Thanks for your help Remy.
I now find, remove and store the anchor fragment
before I URL encode the individual parameters.
After urlencode I then reattach the anchor fragment.
If I encounter links/urls in documents that use
non-encoded '#' as part of query params...
Well... Tough luck :)
best regards
Thomas Schlz