Bug Tracker

Ticket #7945 (closed bug: fixed)

Opened 4 years ago

Last modified 3 years ago

jQuery.param thinks that { jquery: "1.4.2" } is a jQuery object

Reported by: anton@… Owned by:
Priority: high Milestone: 1.5.1
Component: ajax Version: 1.5
Keywords: Cc:
Blocking: Blocked by:

Description

I stumbled upon a bug where .param thought that { jquery: "1.4.2" } is a jQuery object and tried to iterate over it as it was an array. The result was undefined=undefined instead of jquery=1.4.2.

I made a commit fixing the problem and opened a pull request here:  https://github.com/jquery/jquery/pull/174 but it was closed.

I was asked to clarify about the use case so here is the real world example. I am working on a feature that will collect some statistical data from pages where our widget is installed. I started with popular frameworks, and my code sends key/value data where key is a framework name and value is its version.

Now every time I try to send something like { "jquery": "1.4.2" } via .ajax, the server gets undefined=undefined in its POST data. And that applies to any dictionary that has "jquery" string as a key.

--

The second comment was that we can't use instanceof since there is a possibility that an object was created by some other jQuery instance. That makes sense. My initial approach was to check if a.jquery is a function. That covers multiple jQuery instances problem.

As Paul said in the comment to the pull request above, I got some helpful advise from Ben Alman so we might want his feedback on this issue as well.

I can make another pull request once we agree on the approach here.

Anton

Change History

comment:1 Changed 4 years ago by paul.irish

For context, Anton is the lead js dev at Disqus.

comment:2 Changed 4 years ago by anton@…

So, I went ahead and made another (now proper) pull request:  https://github.com/jquery/jquery/pull/181. Let me know what do you think.

comment:3 Changed 4 years ago by rwaldron

  • Priority changed from undecided to blocker
  • Status changed from new to open
  • Component changed from unfiled to ajax

comment:4 Changed 4 years ago by dmethvin

  • Milestone changed from 1.next to 1.6

Just moving this to 1.6 so we can consider the patch.

comment:5 Changed 4 years ago by Anton Kovalyov

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

Fixes #7945. Make jQuery.param() serialize plain objects with a property named jquery correctly.

Changeset: fdd4101fe93321f33b916a92b5def1328ea331b3

 https://github.com/jquery/jquery/commit/fdd4101fe93321f33b916a92b5def1328ea331b3

Last edited 4 years ago by paul.irish (previous) (diff)

comment:6 Changed 4 years ago by jitter

  • Priority changed from blocker to high
  • Version changed from 1.4.4 to 1.5
  • Milestone changed from 1.6 to 1.5.1
Note: See TracTickets for help on using tickets.