[REBOL] Re: decode-cgi bug (?)
From: tomc:darkwing:uoregon at: 9-Feb-2004 15:24
ok here is a version that allows multiple &'s
decode-cgi: func [args [any-string!] /raw
/local cgi-block name value mark here
][
all[empty? args return ""]
structural: make bitset! "+&=%"
non-struct: complement structural
xchar: make bitset! {0123456789ABCDEFabcdef}
safe-xchar: make bitset! {23456789ABCDEFabcdef}
cgi-block: make block! 16
spc: [mark: #"+" (change :mark " ")]
hex: [mark: #"%" 2 xchar (change/part :mark dehex copy/part :mark 3 3)
:mark]
safe-hex: [mark: #"%"
[safe-xchar xchar (change/part :mark dehex copy/part
:mark 3 3) :mark] |
[2 xchar (change :mark "!" )]
]
parse/all args [
any #"&"
any[(name: copy "" value: copy "" here: copy "")
copy name some [non-struct | spc | safe-hex]
(all[not raw name: vet-word trim name]
either none? here: find cgi-block to set-word! name[
insert/only tail cgi-block to set-word! name
insert/only here: tail cgi-block none
][here: next here])
opt[#"="
opt[copy value some [non-struct | spc | hex]
(either none? first here
[change here value]
[either not block? first here
[poke here 1 to block! reduce[first here
value]]
[insert/only tail first here value]
]
)
]
]
[some[#"&"] | end]
]
]
cgi-block
]
On Mon, 9 Feb 2004, Tom Conlin wrote: