Skip to content

Commit 2263134

Browse files
committed
Fix #10863. Allow newlines in JSON data- attributes.
1 parent c01e022 commit 2263134

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/data.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var rbrace = /^(?:\{.*\}|\[.*\])$/,
1+
var rbrace = /(?:\{[\s\S]*\}|\[[\s\S]*\])$/,
22
rmultiDash = /([A-Z])/g;
33

44
jQuery.extend({

test/unit/data.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,5 +646,12 @@ test( "Only check element attributes once when calling .data() - #8909", functio
646646

647647
// clean up data cache
648648
element.remove();
649-
650649
});
650+
651+
test( "JSON data- attributes can have newlines", function() {
652+
expect(1);
653+
654+
var x = jQuery("<div data-some='{\n\"foo\":\n\t\"bar\"\n}'></div>");
655+
equal( x.data("some").foo, "bar", "got a JSON data- attribute with spaces" );
656+
x.remove();
657+
});

0 commit comments

Comments
 (0)