Bug Tracker

Modify

Ticket #7524 (closed bug: fixed)

Opened 3 years ago

Last modified 3 years ago

Calling $.fn.data without arguments on a non-DOMelement in 1.4.4

Reported by: timmolendijk Owned by: snover
Priority: blocker Milestone: 1.5
Component: data Version: 1.4.4
Keywords: regression Cc:
Blocking: Blocked by:

Description

Try the following code in 1.4.3 and then in 1.4.4:

$({tim: 28}).data()

In 1.4.3 the expected data object is returned, in 1.4.4 a TypeError in thrown: "Cannot read property 'length' of undefined"

The problem is in line 1250, in which it is assumed that the data object has an "attributes" property (which is obviously a valid assumption for DOM nodes with nodeType 1 but not for many other object types).

Change History

comment:1 Changed 3 years ago by boushley

Here's a simple jsFiddle for this use case.

Version 0, edited 3 years ago by boushley (next)

comment:2 Changed 3 years ago by rwaldron

  • Status changed from new to closed
  • Resolution set to duplicate

Confirmed

comment:4 Changed 3 years ago by rwaldron

  • Priority changed from undecided to low
  • Resolution duplicate deleted
  • Status changed from closed to reopened
  • Component changed from unfiled to data

comment:5 Changed 3 years ago by rwaldron

  • Milestone changed from 1.5 to 1.4.5

comment:6 Changed 3 years ago by snover

Calling $.fn.data on a plain JS object with no argument will just return the JS object. Is there actually a use case here?

Last edited 3 years ago by snover (previous) (diff)

comment:7 Changed 3 years ago by timmolendijk

Use case; sometimes it's a custom (not necessarily plain) JS object, sometimes it's a DOM element. That's where the $.data API shines, as you can just treat them all the same. This bug messes up this unity.

comment:8 Changed 3 years ago by snover

  • Keywords regression added
  • Priority changed from low to blocker
  • Status changed from reopened to open

I wish, I wish, I wish this wasn’t a regression.

comment:9 Changed 3 years ago by snover

  • Owner set to snover
  • Status changed from open to assigned

comment:10 Changed 3 years ago by john

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

Landed.

comment:11 Changed 3 years ago by jitter

  • Milestone changed from 1.4.5 to 1.5

Move fixed tickets to appropriate milestone

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.