Ticket #7231 (closed bug: duplicate)
$.fn.data and html5 data- attributes - broken implementation
|Reported by:||nate@…||Owned by:|
The type detection built into retrieval of values from html5 data- attributes via $.fn.data in its current implementation is horribly broken.
Support was provided for booleans true and false, null, and complex objects (arrays and object hashes). These are all handled by setting the attribute's value to the JSON-encoded version of the data. However, the same treatment was not provided for parsing strings.
data-name='"joe"' currently parses as a string with the value '"joe"', when it should in fact be parsed as string 'joe' - no quotes. Current implementation does not allow for passing a string with the value "true", "false", "null", nor a stringified version of a complex JSON object.
Invalid JSON values (ie: data-name="joe") can be made to fallback on string value rather than generating a JSON error. But strings in their proper JSON encoded form must be properly supported.
If support for booleans, null and complex objects is going to stay, all data- attributes should be parsed with parseJSON, not a hacked-together soup of sometimes-parsing as JSON, sometimes not. If there is truly a performance boost from prematurely detecting booleans/nulls/numerics rather than parsing proper JSON, then these shortcut detections should be built directly into the parseJSON function, not in a single place within $.fn.data.
- Keywords needsreview added
- Component changed from unfiled to data
comment:17 Changed 3 years ago by dmethvin
- Status changed from new to closed
- Resolution set to invalid
- Milestone 1.next deleted
comment:23 Changed 3 years ago by dmethvin
- Status changed from closed to reopened
- Resolution invalid deleted
comment:24 Changed 3 years ago by dmethvin
- Status changed from reopened to closed
- Resolution set to duplicate