> OK, testing 1.7 and am finding that my encoded parameter is being decoded
> with decodeURIComponent in toQueryParms:

Yes, but as I said earlier, the decoded version *isn't used*. It's
only decoded to check it (at least, that's my theory; they decode it
without using the result, so...). I'm surprised that it gets decoded
the way it does (but I've confirmed it), but it doesn't matter --
you're supplying the string, and if you do that with 1.7, the actual
string you supply is what's actually sent with the request. I've
walked through the code. The relevant bits are in

    var params = Object.isString(this.options.parameters) ?
          this.options.parameters :

...thus `params` is set to the string you pass in, no transformation

    if (params && this.method === 'get') {
      this.url += (this.url.include('?') ? '&' : '?') + params;

...thus if you're doing a GET, your string gets appended to the URL.

    this.parameters = params.toQueryParams();

...the decoding *happens*, but `this.parameters` is not then used.

      this.body = this.method == 'post' ? (this.options.postBody ||
params) : null;

...thus if you're doing a POST and you haven't supplied the `postBody`
option, your original string (still unmodified) is sent.

I've tested this, posting to a page that just echoes what it gets, and
the result is that I see the "p_division" parameter with the (decoded)
value of "Sr 16+" -- exactly what it should be.

This is not true with Prototype 1.6.1, because 1.6.1 takes your string
on a pointless round-trip from string to object and back again, and
the issue with decodeURIComponent not handling the + causes trouble.
But not on 1.7.

Off-topic: What are you using to encode that string in the first
place? Because really all of this fuss can be side-stepped if you
encode it as "Sr%2016%2b" (which is perfectly correct) rather than
using the + instead of %20. (`encodeURIComponent` will give the the
%20 version.) The decoded string is the same.

Here's my test page: http://pastie.org/1428234 (but without the
showparams.jsp it calls, not sure how much it's worth).

T.J. Crowder
Independent Software Engineer
tj / crowder software / com
www / crowder software / com

On Jan 4, 4:03 am, kstubs <kst...@gmail.com> wrote:
> OK, testing 1.7 and am finding that my encoded parameter is being decoded
> with decodeURIComponent in toQueryParms:
>   function toQueryParams(separator) {
>     var match = this.strip().match(/([^?#]*)(#.*)?$/);
>     if (!match) return { };
>     return match[1].split(separator || '&').inject({ }, function(hash, pair)
> {
>       if ((pair = pair.split('='))[0]) {
>         var key = decodeURIComponent(pair.shift()),
>             value = pair.length > 1 ? pair.join('=') : pair[0];
>         if (value != undefined) value = decodeURIComponent(value);
>         if (key in hash) {
>           if (!Object.isArray(hash[key])) hash[key] = [hash[key]];
>           hash[key].push(value);
>         }
>         else hash[key] = value;
>       }
>       return hash;
>     });
>   }
> So, my original value:    Sr 16+
> Encoded as:                 Sr+16%2b
> Is decoded to:               Sr+16+
> And this is wrong.  Any ideas, am I doing something wrong do you suppose?
> Karl..

You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptacul...@googlegroups.com.
To unsubscribe from this group, send email to 
For more options, visit this group at 

Reply via email to