Bug Tracker

Ticket #6481 (closed bug: fixed)

Opened 5 years ago

Last modified 21 months ago

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:
Blocking: Blocked by:

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

comment:2 Changed 4 years ago by john

  • Priority set to undecided
  • Status changed from new to closed
  • Resolution set to fixed

comment:3 Changed 4 years ago by anonymous

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

comment:4 Changed 4 years ago by rekna1@…

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

comment:5 Changed 4 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 4 years ago by dmethvin

  • Status changed from closed to reopened
  • Resolution fixed deleted
  • Milestone 1.4.3 deleted

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 4 years ago by snover

  • Keywords regression added

comment:8 Changed 4 years ago by rwaldron

  • Keywords param,regression,ajaxrewrite added; param regression removed

comment:9 follow-up: ↓ 10 Changed 4 years ago by dmethvin

  • Milestone set to 1.6

comment:10 in reply to: ↑ 9 ; follow-up: ↓ 11 Changed 4 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 4 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 4 years ago by snover

  • Priority changed from undecided to blocker
  • Status changed from reopened to open
  • Summary changed from $.param should treat empty arrays/objects like empty strings to revert $.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 4 years ago by dmethvin

#8687 is a duplicate of this ticket.

comment:14 Changed 4 years ago by john

  • Status changed from open to closed
  • Resolution set to fixed

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

comment:15 Changed 4 years ago by john

  • Type changed from enhancement to bug

comment:16 Changed 4 years ago by addyosmani

#8902 is a duplicate of this ticket.

comment:17 Changed 4 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 4 years ago by dmethvin

#9360 is a duplicate of this ticket.

comment:19 Changed 3 years ago by dmethvin

#10292 is a duplicate of this ticket.

comment:20 Changed 21 months ago by dmethvin

#13611 is a duplicate of this ticket.

Note: See TracTickets for help on using tickets.