Encoding a Query String

Hi,

I'm writing a small class to deal URI with query-string encoding/decoding.
I'm a bit unsure however as to what needs to be encoded/decoded and what
doesn't. I've had a look at several classes on the net and they all seem to
do it a little differently.

I've grabbed this relevant section from the HTTP 1.1 spec:

query          = *( uchar | reserved )

pchar          = uchar | ":" | "@" | "&" | "=" | "+"
uchar          = unreserved | escape
unreserved     = ALPHA | DIGIT | safe | extra | national

escape         = "%" HEX HEX
reserved       = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+"
extra          = "!" | "*" | "'" | "(" | ")" | ","
safe           = "$" | "-" | "_" | "."
unsafe         = CTL | SP | <"> | "#" | "%" | "<" | ">"
national       = <any OCTET excluding ALPHA, DIGIT,
                 reserved, extra, safe, and unsafe>


Lets say I wish to send the following set of name/value pairs:

name = Mr Joe G. Bloggs
houseno = #16
salary = $50,000

For the internet explorer implementation of the encoding I get the
following:

?name=Mr%20Joe%20G.%20Bloggs&houseno=%2316&%2450%2C000

So it encodes safe "$" but not the safe ".", is this correct?

Generally, I would assume that everything needs to be encoded except for the
safe characters, is this right and is IE's implementation wrong? I read that
you MUST encoded the unsafe/reserved characters etc, but you MAY encode any
others, would this mean IE's implementation is correct?

If your interested, I'm using the Microsoft JScript 5.5 Engine's
encodeURIComponent() function to test these query-strings.

Thanks,

Jim.


Disclaimer
Information in this E-mail and in any attachments is confidential
and intended solely for the attention and use of the named addressee(s)
This information may be subject to legal, professional or other privilege.

If you are not the intended recipient, or a person responsible for 
delivering it to the intended recipient, you are not authorised to
and must not disclose, copy distribute, or retain this message or any part
of it.
If you have received this message in error please contact us at once,
so that we may take the appropriate action and avoid troubling you further.

Received on Thursday, 1 March 2001 06:03:42 UTC