on 1/11/01 6:11 AM, LiangTyan Fui at [EMAIL PROTECTED] wrote:

> 
> The browser constructs the the following string and pass onto the server:
> http://localhost/cgi-bin/echo.mt?option=1&option=2&option=3
> 
> Suppose you are using a split command to parse the query string in the
> echo.mt script:
> 
> put $QUERY_STRING into x
> split x by "&" and "="
> put keys(x) into xKeys
> 
> you'll get only "option" in xKeys, and x["option"] gives you "3".
> 
> Hmm..... should I bug report this?

It's not a bug - split is behaving correctly according to the spec - it's
just that this spec makes it tantalisingly close to a handy parser for URL
strings, but not quite right.  But the thing to do is use this as a cue to
define the spec you do want for that purpose, and implement it - eg:

    function splitQueryString qs --> array
      set the itemdelimiter to "&"
      repeat for each item p in qs
        put space into char offset("=", p) of p -- or use split in 2.4
        put urlDecode(word 1 of p) into k
        put urlDecode(word 2 to -1 of p) into v
        --
        -- may or may not want this, depending on what you're doing
        if v = empty then put true into v
        --
        get formdata[k]
        if it <> empty then put it & "," before v
        put v into formdata[k]
      end repeat
      return queryparms
    end splitQueryString

This will handle the multi-option case, and is also neater because it's
specialised for handling query strings - so it can do the URLdecoding.  If
you had a parallel function that parsed data 'POST'ed instead of sent in the
query string, then you could isolate the encoding issue - call one or other
function, and then either way have an array of parameters and values.

(Note that this implementation has chosen to force every key to have a
value.   That's because it relies on empty to indicate that a key hasn't
been defined yet.  If there was an atomic test for 'is-a-key' (is there?)
one could use that - or if you really want it, go the extra mile and keep a
second array to show whether a key has been encountered already.)

  Ben Rubinstein               |  Email: [EMAIL PROTECTED]
  Cognitive Applications Ltd   |  Phone: +44 (0)1273-821600
  http://www.cogapp.com        |  Fax  : +44 (0)1273-728866



Archives: http://www.mail-archive.com/[email protected]/
Info: http://www.xworlds.com/metacard/mailinglist.htm
Please send bug reports to <[EMAIL PROTECTED]>, not this list.

Reply via email to