[REBOL] Re: to-url
From: tim:johnsons-web at: 5-Jan-2003 18:36
* Carl Read <[carl--cybercraft--co--nz]> [030105 18:19]:
> On 06-Jan-03, Tim Johnson wrote:
> > Hello :
> > I have some questions about to-url here:
> > supose I want to create a query-string in a url
> > that has letters like "?=&" inside of
> > the values.
> >>> to-url "Father & sons"
> > == Father & sons
> > ;yikes, shouldn't we get Father %26 son ('&' is hex 26, right?)
> > ; decoding this will give incorrect results, I think...
>
> > Comments and suggestions welcome
>
> I just searched google for "a & b" to see how it'd make its URL, and
> this is what it returned...
>
> http://www.google.co.nz/search?q=a+%26+b&ie=ISO-8859-1&hl=en&btnG=Google+Search
>
> My guess would be that you'd convert to %26 if it's part of some text,
> but leave as-is if it's for breaking up the query. (A guess mind -
> others here will know the rules I'm sure.)
Hi Carl:
Great minds run in the same gutter! It would seem that rebol's
native funcs aren't taking this into consideration.
; I just churned this out. Hopefully someone has a better
; solution, if not, pointers are welcome to docs on
; other chars to be escaped.
url-str: def[str[string!]][
encode: [#"%" "%25" #"&" "%26" #"=" "%3D" #" " " "]
new-str: make string! (length? str) * 2 ;oh, just an estimate
repeat char str[
either found: select encode char
[append new-str found]
[append new-str char]
]new-str
]
-tim-
> --
> Carl Read
>
> --
> To unsubscribe from this list, please send an email to
> [rebol-request--rebol--com] with "unsubscribe" in the
> subject, without the quotes.
--
Tim Johnson <[tim--johnsons-web--com]>
http://www.alaska-internet-solutions.com
http://www.johnsons-web.com