Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 7cf4a29

Browse files
committed
fix(angular.element): do not break on cleanData() if _data() returns undefined
This shouldn't happen in supported jQuery versions (2+), but if someone uses the unsupported 1.x version the app will break. The change that causes this new behavior was introduced in b7d396b. Even though jQuery 1.x is not supported, it is worth avoiding the unnecessary breakage (given how simple). Fixes #16641 Closes #16642
1 parent 7dd6c87 commit 7cf4a29

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/Angular.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1909,7 +1909,7 @@ function bindJQuery() {
19091909
jqLite.cleanData = function(elems) {
19101910
var events;
19111911
for (var i = 0, elem; (elem = elems[i]) != null; i++) {
1912-
events = jqLite._data(elem).events;
1912+
events = (jqLite._data(elem) || {}).events;
19131913
if (events && events.$destroy) {
19141914
jqLite(elem).triggerHandler('$destroy');
19151915
}

test/jqLiteSpec.js

+6
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,12 @@ describe('jqLite', function() {
501501
expect(jqLite(c).data('prop')).toBeUndefined();
502502
});
503503

504+
it('should not break on cleanData(), if element has no data', function() {
505+
var selected = jqLite([a, b, c]);
506+
spyOn(jqLite, '_data').and.returnValue(undefined);
507+
expect(function() { jqLite.cleanData(selected); }).not.toThrow();
508+
});
509+
504510

505511
it('should add and remove data on SVGs', function() {
506512
var svg = jqLite('<svg><rect></rect></svg>');

0 commit comments

Comments
 (0)