Skip to content

Commit 6805fc2

Browse files
rwaldrontimmywil
authored andcommitted
Landing pull request 461. Adds a due diligence check for pre-defined data-* attrs during removal. Fixes #10026.
More Details: - jquery#461 - http://bugs.jquery.com/ticket/10026
1 parent 1a738cb commit 6805fc2

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/data.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ jQuery.extend({
167167

168168
delete thisCache[ name ];
169169

170+
// Check the actual element for predefined data-* attrs, #10027
171+
if ( jQuery.attr( elem, "data-" + name ) ) {
172+
jQuery.removeAttr( elem, "data-" + name );
173+
}
174+
170175
// If there is no data left in the cache, we want to continue
171176
// and let the cache object itself get destroyed
172177
if ( !isEmptyDataObject(thisCache) ) {

test/unit/data.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ test("jQuery.data supports interoperable removal of hyphenated/camelCase propert
568568
"some-json": '{ "foo": "bar" }'
569569
};
570570

571-
expect( 27 );
571+
expect( 29 );
572572

573573
jQuery.each( datas, function( key, val ) {
574574
div.data( key, val );
@@ -581,4 +581,15 @@ test("jQuery.data supports interoperable removal of hyphenated/camelCase propert
581581
equal( div.data( key ), undefined, "get: " + key );
582582

583583
});
584+
585+
div.remove();
586+
587+
// Covers #10027
588+
div = jQuery("<div data-msg='hello'></div>");
589+
590+
equal( div.data("msg"), "hello", "<div data-msg='hello'></div> has expected data" );
591+
592+
div.removeData("msg");
593+
594+
equal( div.data("msg"), undefined, "data-msg removed correctly" );
584595
});

0 commit comments

Comments
 (0)