[REBOL] Re: decode-cgi bug (?)
From: andreas:bolka:gmx at: 19-Feb-2004 18:02
Thursday, February 19, 2004, 5:18:19 PM, Will wrote:
> there seems to be a bug in your function:
>>> decode-cgi "a=1&b=&c=3"
> == [a: "1" b: "1" c: "3"]
thanks for reporting, will. fixed:
decode-cgi: func [
{Converts CGI argument string to a list of words and value strings.}
args [any-string!] "Starts at first argument word"
/local list nv-pair value name name-chars val
][
add-nv: func [ list name value /local val-ptr ] [
if none? name [ return ]
value: dehex replace/all any [ value (copy "") ] "+" " "
either val-ptr: find list to-set-word name
[ change/only next val-ptr compose [ (first next val-ptr) (value) ] ]
[ append list compose [ (to-set-word name) (value) ] ]
]
list: make block! 8
name-chars: complement charset "&="
nv-pair: [ copy name some name-chars
(val: none) value (add-nv list name val) | "&" ]
value: [ "=" value | "&" | [ copy val to "&" skip | copy val to end ] ]
parse/all args [ some nv-pair | none ]
list
]
--
Best regards,
Andreas