Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

Inconsistent CGI decoding behaviour

 [1/4] from: hallvard::ystad::helpinhand::com at: 21-Jan-2002 12:00


I tried make object! decode-cgi system/options/cgi/query-string in a CGI script and supplied a URL like this: http://www.server/cgi-bin/rebolscript.r?key=value&=nothing Obviously, the URL is not too well constructed, since the key for the value "nothing" is missing. Nevertheless, such URLs do get requested from time to time. Now here's what I got from the script: ** Script Error: Expected one of: word! - not: none! ** Where: to-set-word ** Near: to set-word! :value Is this normal behaviour? Do I have to try and catch to get my CGI parameters? Then why is this URL OK: http://www.server/cgi-bin/rebolscript.r?key=value&nothingAs I request this last URL, make object! decode-cgi system/options/cgi/query-string will become: make object! [ key: "value" nothing: "" ] So why the inconsistency? ~H

 [2/4] from: ryanc:iesco-dms at: 21-Jan-2002 10:56


-- Unable to decode HTML file!! --

 [3/4] from: ryanc:iesco-dms at: 21-Jan-2002 12:10


Hey Hallvard, In my opinion "garbage in, garbage out." But since the issue seemed so straight forward, I could'nt resist making the fix. 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 ][ 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 "=" "=" (if name [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 ]
>> probe make object! probe decode-cgi "t=1&=ff"
[t: "1" "ff"] make object! [ t: "1" ]
>>
This I will leave it up to you to test it and submit to feedback. --Ryan

 [4/4] from: hallvard:ystad:helpinhand at: 22-Jan-2002 10:07


Ryan, your little change in 'decode-cgi works perfectly well, thanks. I submitted it to feedback, and take it this "bug" is simply a blunder that will be fixed in the next release. ~H Dixit Ryan Cole (21.10 21.01.2002):