I've noticed there's a problem with Rebol's standard decode-cgi function.
Here's the source:
>> source decode-cgi
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 equate value name val
][
    plus-to-space: func [arg /local seek chr] [
        if any [none? arg empty? arg] [return ""]
        seek: arg
        while [seek: find seek #"+"] [
            change seek #" "
            seek: next seek
        ]
        head arg
    ]
    list: make block! 8
    equate: [copy name to "=" "=" (append list to-set-word name) value]
    value: ["&" (append list copy "") | [copy val to "&" "&" | copy val to
end]
        (append list either none? val [copy ""] [form dehex plus-to-space
val])]
    parse/all args [some equate | none]
    list
]


Note that 'plus-to-space is created inside 'decode-cgi each time it's used.
It can also be easily replaced with 'replace/all. Also, CRLF aren't
converted to Rebol's newline. This replacement function should fix these
problems:

Decode-CGI: function [
    {Converts CGI argument string to a block of set-words and value
strings.}
    Args [any-string!]    "Starts at first argument word."
    ] [
    Block Name Value
    ] [
    Block: make block! 10
    parse/all Args [
        any [
            copy Name to #"=" skip (
                append Block to-set-word Name
                )
            [
                #"&" (
                    append Block copy ""
                    )
                | [copy Value to "&" "&" | copy Value to end] (
                    append Block either none? Value [
                        copy ""
                        ] [
                        replace/all dehex replace/all Value #"+" #" " CRLF
newline
                        ]
                    )
                ]
            ]
        end
        ]
    Block
    ]

I've sent it in to feedback.

Andrew Martin
ICQ: 26227169 http://valley.150m.com/
-><-


-- 
To unsubscribe from this list, please send an email to
[EMAIL PROTECTED] with "unsubscribe" in the 
subject, without the quotes.

Reply via email to