Bug Tracker

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#7241 closed bug (duplicate)

.data() doesn't parse JSON strings, but accepts all other JSON notation

Reported by: leo@… Owned by:
Priority: low Milestone: 1.5
Component: data Version: 1.4.3
Keywords: string support data Cc:
Blocked by: Blocking:

Description

Regarding the broken .data() functionality in jQuery 1.4.3

It is expected that .data() can be used to pass a JSON encoded variable into a data attribute and having it fetched in the same structure with .data() by the client. This is true for null, boolean, number, array and object but not strings!

What I expect: To retain the structure, variables & types of the data.

What actually happens: Strings are either unparsed or accidentally parsed as something else. There is no functionality for accurately retaining the contents of strings.

More info on the problem here: http://www.reddit.com/r/programming/comments/ds42b/jquery_143_released/c12l6z9

And a visual of how the data parsing should work...

When I use:

$("div").data("variable");

The result from .data() should simply be equivalent to this:

try{
   var variable = jQuery.parseJSON( $("div").attr("data-variable") );
}catch(e){
   var variable = $("div").attr("data-variable");
}

But instead it is not simply parsing JSON first, it is parsing everything except strings, and leaving anything else as raw, unparsed strings.

Change History (2)

comment:1 Changed 7 years ago by addyosmani

Component: unfileddata
Keywords: string support data added
Priority: undecidedlow
Resolution: duplicate
Status: newclosed

The bug submitted sounds a lot like #7231. I'll reference your ticket in the other thread but will be closing this as a duplicate as both refer to the broken string support.

comment:2 Changed 7 years ago by addyosmani

Duplicate of #7231.

Note: See TracTickets for help on using tickets.