PDA

View Full Version : [OPEN] [2.0a1] [CLOSED] Ext.urlEncode array bug



Const
6 Oct 2007, 4:27 AM
Bug at Ext.urlEncode function at array encoding.



...
for(var i = 0, len = ov.length; i < len; i++) {
buf.push(k, "=", encodeURIComponent(ov[i] === undefined ? '' : ov[i]), "&");
}
...

need to replace with


...
for(var i = 0, len = ov.length; i < len; i++) {
buf.push(k, "[",i,"]=", encodeURIComponent(ov[i] === undefined ? '' : ov[i]), "&");
}
...




P.S. bug come from ext 1.1.1

mystix
6 Oct 2007, 8:03 AM
pls explain.

[edit]
your suggested "fix" would cause


Ext.urlEncode({a:1, b:[1, 2, 3]});


to return


"a=1&b[0]=1&b[1]=2&b[2]=3"


instead of


"a=1&b=1&b=2&b=3"


which runs contrary to the intended purpose as defined in the API docs, and would also be interpreted differently by any server side language than what was originally intended.

p.s. there's also a reason for the calls to the encodeURIComponent() method throughout the Ext.urlEncode method -- there shouldn't be any "["s and "]"s appearing in an URL-encoded string. are you sure you know what you're doing?

jack.slocum
6 Oct 2007, 11:48 AM
Ext does it correctly. Take a look at the spec. I would imagine you are using it with PHP and want it to come in as an array? In that case, the php requirement is that you name the variable with a [] at the end. E.g. b[].