URL encoding ?
[1/7] from: jean:holzammer:faedv-n:bayern at: 24-Oct-2002 10:39
Hi,
I'd like to encode a URL.
URL: http://www.bla.org/cgi-bin/bla.cgi?a=1&b=xyz
I tried:
>> mold to-url "http://www.bla.org/cgi-bin/bla.cgi?a=1&b=xyz"
== "http://www.bla.org/cgi-bin/bla.cgi?a=1&b=xyz"
I need:
http%3A%2F%2Fwww.bla.org%2Fcgi-bin%2Fbla.cgi%3Fa%3D1%26b%3Dxyz
mold to-url will only encode some (=E4=F6=FC...) special characters, but not all
:(
The encoded URL is to be passed as argument for a cgi-script !
http://abc.com/cgi-bin/myscript.cgi?id=7&title=sometext&url=http%3A%2F%2Fwww
.bla.org%2Fcgi-bin%2Fbla.cgi%3Fa%3D1%26b%3Dxyz
Any ideas ??
Jean
[2/7] from: gscottjones::mchsi::com at: 24-Oct-2002 6:56
From: "Holzammer, Jean"
> I'd like to encode a URL.
>
> URL: http://www.bla.org/cgi-bin/bla.cgi?a=1&b=xyz
...
> I need:
> http%3A%2F%2Fwww.bla.org%2Fcgi-bin%2Fbla.cgi%3Fa%3D1%26b%3Dxyz
Hi, Jean,
No built in function will do this, at least to my knowledge. The following
appears to work:
url: "http://www.bla.org/cgi-bin/bla.cgi?a=1&b=xyz"
replace/all url ":" "%3A"
replace/all url "/" "%2F"
replace/all url "?" "%3F"
replace/all url "=" "%3D"
replace/all url "&" "%26"
url: to-url url
;== http%3A%2F%2Fwww.bla.org%2Fcgi-bin%2Fbla.cgi%3Fa%3D1%26b%3Dxyz
The final to-url should catch all those other special characters, if any.
HTH.
--Scott Jones
[3/7] from: jason:cunliffe:verizon at: 24-Oct-2002 5:57
Hi Jean
This is how Vanilla [ http://www.langreiter.com/space/Vanilla ] does it:
opt-in: charset "
*-.1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz"
url-encode: make function! [ str[string!] /re ] [
if re [ insert opt-in "%:/&=" ]
rslt: make string! ( (length? str ) * 3 )
foreach chr str [
either ( find opt-in chr )
[append rslt to-string (either(chr == #" ")["+"][chr]) ]
[append rslt
join "%" [back back tail(to-string(to-hex(to-integer chr)))]
]
]
rslt
]
>> url-encode "http://www.bla.org/cgi-bin/bla.cgi?a=1&b=xyz"
== {http%3A%2F%2Fwww.bla.org%2Fcgi-bin%2Fbla.cgi%3Fa%3D1%26b%3Dxyz}
./Jason
----- Original Message -----
From: "Holzammer, Jean" <[Jean--Holzammer--faedv-n--bayern--de]>
To: <[rebol-list--rebol--com]>
Sent: Thursday, October 24, 2002 4:39 AM
Subject: [REBOL] URL encoding ?
Hi,
I'd like to encode a URL.
URL: http://www.bla.org/cgi-bin/bla.cgi?a=1&b=xyz
[4/7] from: jean:holzammer:faedv-n:bayern at: 24-Oct-2002 14:31
Thanks, too.
[5/7] from: andreas:bolka:gmx at: 24-Oct-2002 18:50
Thursday, October 24, 2002, 10:57:38 AM, Jason wrote:
> This is how Vanilla [ http://www.langreiter.com/space/Vanilla ] does it:
don't forget to give proper credit, this version of url-encode is
based on the url-encode from [tomc--cs--uoregon--edu]
--
Best regards,
Andreas mailto:[andreas--bolka--gmx--net]
[6/7] from: tomc:darkwing:uoregon at: 24-Oct-2002 12:25
thanks Andres
On Thu, 24 Oct 2002, Andreas Bolka wrote:
[7/7] from: jason:cunliffe:verizon at: 24-Oct-2002 15:37
Andreas
> don't forget to give proper credit, this version of url-encode is
> based on the url-encode from [tomc--cs--uoregon--edu]
My bad... Thanks for the reminder.
I have too much commented code these days, so I keep my comment color scheme
turned way down. That's how I stupidly missed the credit line sitting right
above url-encode function in vanilla/apps/simplespace.r
cheers
./Jason