#126 enhancement
Peter Gyongyosi

toQueryString fails with Arrays

Reported by Peter Gyongyosi | May 29th, 2008 @ 06:46 PM | in 2.0

If you try to use toQueryString on a Hash that was created from an Array, the results include the built-in functions. See the following test case I added to the Hash unit test:

  testArrayToQueryString: function(){
    var test = new Array();
    test = ["a", "b", "c"];
    this.assertEqual("0=a&1=b&2=c", $H(test).toQueryString());

The answer we actually got is


This is especially annoying if you try to pass an Array as a parameter in an Ajax.Request, like in this test case:

  testArrayRequest: function() {
    this.assertEqual("", $("content").innerHTML);
    this.assertEqual(0, Ajax.activeRequestCount);

    var request = new Ajax.Request("../fixtures/hello.js", {
                        asynchronous: false,
                        parameters: new Array(),
                        method: 'GET',
                        evalJS: 'force'

    this.assertEqual("../fixtures/hello.js", request.url);


Even though we passed an empty array as parameters, the GET url is filled with the code gibberish as seen above, which is no surprise as Ajax.Request::request() ultimately uses toQueryString from Hash.

I could only test this with FF2 and Konqueror on Linux at the moment, but it should be easy to reproduce this on other platforms using the test cases above.

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

The Prototype JavaScript library.

Shared Ticket Bins


Referenced by