Saturday, June 1, 2002, 4:03:14 AM, Andrew wrote:

> I've noticed there's a problem with Rebol's standard decode-cgi
> function.

[...source...]

> Note that 'plus-to-space is created inside 'decode-cgi each time
> it's used. It can also be easily replaced with 'replace/all.

actually plus-to-space is a scaled down version of replace/all (have a
look at source replace). however, in the sense of reuse, using replace
is ok ;)

> Also, CRLF aren't converted to Rebol's newline.

this is most likely an application level problem - normal CRLFs should
not pass up to decode-cgi, only CRLFs which are hex-encoded. and i
think those should be passed thru to the app.

HOWEVER, there are two more important problems (imho):

1. decode-cgi is not able to properly parse "empty params" like name2
in "name1=val1&name2&name3=val3"

>> decode-cgi "name1=val1&name2&name3=val3"
== [name1: "val1" name2&name3: "val3"]

2. decode-cgi requires post-processing when it parses a string
containing multiple parameters with the same name:
"name=val1&name=val2"

>> decode-cgi "name=val1&name=val2"
== [name: "val1" name: "val2"]

this list is quite ok, but it does not make sense to 'make object!
this or even 'do it. naturally, multiple parameters with the same name
map to a list, imho:

>> decode-cgi "name=val1&name=val2"
== [name: ["val1" "val2"]]

so here is another patched decode-cgi :) [also submitted to feedback]

; --- snip ---
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 name-chars val plus-to-space
][
   add-nv: func [ list name value /local val-ptr ] [
      name: to-set-word name
      value: either none? value 
         [ copy "" ] 
         [ form dehex (replace/all value "+" " ") ]

      either none? val-ptr: find list name [
         append list compose [ (name) (value) ] 
      ] [ 
         idx: index? next val-ptr
         poke list idx compose [ (pick list idx) (value) ] 
      ]
   ]

   list: make block! 8
   name-chars: complement charset "&="
   equate:     [ copy name some name-chars value]
   value:      [     "=" value 
               | "&" (add-nv list name "") 
               |     [ copy val to "&" "&" | copy val to end ]
                  (add-nv list name val)
            ]

   parse/all args [some equate | none]
   list
]
; --- snap ---

-- 
Best regards,
 Andreas                            mailto:[EMAIL PROTECTED]

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

Reply via email to