Bug Tracker

Opened 11 years ago

Closed 10 years ago

Last modified 8 years ago

#6481 closed bug (fixed)

revert $.param should treat empty arrays/objects like empty strings

Reported by: temp01 Owned by:
Priority: blocker Milestone: 1.6
Component: ajax Version: 1.4.2
Keywords: param, regression, ajaxrewrite Cc:
Blocked by: Blocking:

Description

$.param ignores the key completly if the value is an empty object or array:

$.param({"foo": {"bar": []} });         // -> ""
$.param({"foo": {"bar": [], foo: 1} }); // -> "foo%5Bfoo%5D=1"
$.param({"foo": {"bar": {}} });         // -> ""

Empty values should be treated like empty strings i.e. (expected output):

$.param({"foo": {"bar": []} });         // -> "foo%5Bbar%5D="
$.param({"foo": {"bar": [], foo: 1} }); // -> "foo%5Bbar%5D=&foo%5Bfoo%5D=1""foo%5Bfoo%5D=1"
$.param({"foo": {"bar": {}} });         // -> "foo%5Bbar%5D="

Change History (20)

comment:2 Changed 11 years ago by john

Priority: undecided
Resolution: fixed
Status: newclosed

comment:3 Changed 11 years ago by anonymous

Wish this would have been configurable (like using "traditional") for backwards compatibility.

comment:4 Changed 11 years ago by rekna1@…

This breaking previous behaviour !! You can not simply change this behaviour.. it breaks existing code!

comment:5 Changed 11 years ago by anonymous

Like mentioned in http://forum.jquery.com/topic/change-of-behavior-in-1-4-4-because-of-bug-6481, it think the default implementation should be the way the browser does it... there is no element for an empty array (cfr the example with checkboxes with the same name attribute!!! )

comment:6 Changed 10 years ago by dmethvin

Milestone: 1.4.3
Resolution: fixed
Status: closedreopened

Reopened for possible reversion. See the discussion in the forum thread. Vote on this ticket (at the top of the page) if you 're interested.

comment:7 Changed 10 years ago by snover

Keywords: regression added

comment:8 Changed 10 years ago by Rick Waldron

Keywords: ajaxrewrite added

comment:9 Changed 10 years ago by dmethvin

Milestone: 1.6

comment:10 in reply to:  9 ; Changed 10 years ago by vig

Replying to dmethvin: This fix seems to have got included in the 1.5 version

comment:11 in reply to:  10 Changed 10 years ago by jitter

Replying to vig:

Replying to dmethvin: This fix seems to have got included in the 1.5 version

The "fix" is in since jQuery 1.4.3 .

The ticket was reopened to evaluate if the fix should be reverted as it breaks previous behavior. Check http://forum.jquery.com/topic/change-of-behavior-in-1-4-4-because-of-bug-6481 for the discussion

comment:12 Changed 10 years ago by snover

Priority: undecidedblocker
Status: reopenedopen
Summary: $.param should treat empty arrays/objects like empty stringsrevert $.param should treat empty arrays/objects like empty strings

The problem is that there is no way to serialize an empty array in a way that makes sense in the x-www-form-urlencoded format. foo[bar]= could either mean empty array, empty string, empty object, or null/undefined value, depending upon how the backend chooses to interpret it. Since neither way of serialization is really “correct”, and most backends interpret this as “empty string”, and this breaks traditional mode in quite a bad way (as per the forum thread), I’m marking this to block 1.6 so it can be reverted back to the old behaviour.

comment:13 Changed 10 years ago by dmethvin

#8687 is a duplicate of this ticket.

comment:14 Changed 10 years ago by john

Resolution: fixed
Status: openclosed

Fix for this has been backed out - not something that we're going to try and fix.

comment:15 Changed 10 years ago by john

Type: enhancementbug

comment:16 Changed 10 years ago by addyosmani

#8902 is a duplicate of this ticket.

comment:17 Changed 10 years ago by Se precisar mande um EMAIL gabriel98765432184@…

eu nao entendo nada sera que akguem do jquery poderia ajudar e ao enves de faser otras linguas que ninguem usa por favor traduzam em portugues isso assim muito mais pessoas poderao visualizar e usar mais este site e tenha certeza que eu teria prazer em divulgar

comment:18 Changed 10 years ago by dmethvin

#9360 is a duplicate of this ticket.

comment:19 Changed 10 years ago by dmethvin

#10292 is a duplicate of this ticket.

comment:20 Changed 8 years ago by dmethvin

#13611 is a duplicate of this ticket.

Note: See TracTickets for help on using tickets.