>- Open Your Mind -<
Quoting from my message (03-Sep-00 18:09:43).
a> First, I'm not sure if I'm doing the right thing by changing the
a> special characters in the charset: some of my browsers agree with the
a> previous version, so maybe there's a de-facto standard *I* am not
a> respecting
... and, as a matter of fact, learning more and more about cookies, I've found one
problem. :-) The comma (as well as the semicolon) can be used as a cookie separator.
Here's my newest version of url-encode, complete with comments.
url-encode: func [
"URL-encodes a string."
value [string!] "The string to encode"
/local
url-encoded-string
normal-char
char
] compose [
url-encoded-string: make string! ""
normal-char: (charset [ #"A" - #"Z" #"a" - #"z" #"0" - #"9" "$-_.!*'()"
])
; normal chars are defined as per HTML 4.01 specs, section 17.13.4.1,
referring to RFC 1738, section 2.2
; "+" is not a normal char here because it encodes " "
; "," is not a normal char here because it is a special char as per RFC 2109,
section 4.3.4
parse/all value [
any [
copy char normal-char (append url-encoded-string char) |
copy char " " (append url-encoded-string "+") |
copy char newline (append url-encoded-string "%0D%0A") |
copy char skip (append url-encoded-string reduce ["%" skip tail
(to-hex 0 + first char) -2])
]
]
url-encoded-string
]
Alessandro Pini ([EMAIL PROTECTED])
"Hy. Im HAL 9000, your nu ortoghrapphic corecktor."