Skip to main content

Bug Tracker

Side navigation

#7568 closed bug (fixed)

Opened November 19, 2010 10:19AM UTC

Closed January 31, 2011 03:04PM UTC

Last modified March 09, 2012 11:50PM UTC

jQuery 1.4.4 breaks data for ajax post if 'data' object contains a SUB OBJECT with key named "length"

Reported by: Arnoman Owned by: jitter
Priority: low Milestone: 1.5.1
Component: ajax Version: 1.5
Keywords: Cc:
Blocked by: Blocking:
Description

This kind of problem has already been reported in ticket 5862 and the problem has been fixed for the 'data' object but the problem remains for sub objects contained in 'data' object:

If there is a key named "length" in an sub object contained in the 'data' object, then the data are broken as the value of "length" is used to redefine the "array" length..

jQuery.ajax({
	    type: 'POST',
	    url: url,
	    data: {'test': {'length': 3, 'foo': 'bar'} },
	    success: ...

Data posted are:

test[0]	undefined
test[1]	undefined
test[2]	undefined
Attachments (0)
Change History (7)

Changed November 19, 2010 01:28PM UTC by Arnoman comment:1

That's because of $.each() that think: "ok, you have a length property, then you are an array".

I would like to tell it: "well, no, it's not an array, it's an object that describe something long enough to have a length property"...

But it would for sure respond: "So it's an array-like". Luckily jquery functions do not speak.

Changed November 21, 2010 05:18AM UTC by snover comment:2

component: unfiledajax
priority: undecidedlow
status: newopen

culprit. Should change that to use a for loop instead of $.each.

Changed November 21, 2010 05:18AM UTC by snover comment:3

description: This kind of problem has already been reported in ticket 5862 and the problem has been fixed for the 'data' object but the problem remains for sub objects contained in 'data' object: \ \ If there is a key named "length" in an sub object contained in the 'data' object, then the data are broken as the value of "length" is used to redefine the "array" length.. \ \ jQuery.ajax({ \ type: 'POST', \ url: url, \ data: {'test': {'length': 3, 'foo': 'bar'} }, \ success: ... \ \ Data posted are: \ test[0] undefined \ test[1] undefined \ test[2] undefined \ \ This kind of problem has already been reported in ticket 5862 and the problem has been fixed for the 'data' object but the problem remains for sub objects contained in 'data' object: \ \ If there is a key named "length" in an sub object contained in the 'data' object, then the data are broken as the value of "length" is used to redefine the "array" length.. \ \ {{{ \ jQuery.ajax({ \ type: 'POST', \ url: url, \ data: {'test': {'length': 3, 'foo': 'bar'} }, \ success: ... \ }}} \ \ Data posted are: \ \ {{{ \ test[0] undefined \ test[1] undefined \ test[2] undefined \ }}} \

Changed December 27, 2010 10:37PM UTC by rwaldron comment:4

keywords: → ajaxrewrite

Changed January 31, 2011 02:26PM UTC by jitter comment:5

keywords: ajaxrewrite
milestone: 1.51.5.1
owner: → jitter
status: openassigned

Changed January 31, 2011 03:04PM UTC by Anton M comment:6

resolution: → fixed
status: assignedclosed

Fixes #7568. Follow-up fix for #5862. Objects with a length property weren't serialized properly by jQuery.param.

Changeset: 389c099df686bd104ce0aab3361a94ebf3a05ce6

Changed February 02, 2011 11:31PM UTC by jitter comment:7

version: 1.4.41.5