Skip to content

Commit 5f59199

Browse files
fix($animate): invalid CSS class names should not break subsequent elements
The postDigest handler was not being added if the first element in to modify the CSS classes contained invalid CSS class names. This meant that subsequent valid CSS class changes were not being handled since we were not then adding the handler for those correct cases. Closes angular#12674
1 parent 10cc6de commit 5f59199

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/ng/animate.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ var $$CoreAnimateRunnerProvider = function() {
8181
var $$CoreAnimateQueueProvider = function() {
8282
var postDigestQueue = new HashMap();
8383
var postDigestElements = [];
84+
var handlerAdded = false;
8485

8586
this.$get = ['$$AnimateRunner', '$rootScope',
8687
function($$AnimateRunner, $rootScope) {
@@ -130,8 +131,12 @@ var $$CoreAnimateQueueProvider = function() {
130131

131132
var classesAdded = updateData(add, true);
132133
var classesRemoved = updateData(remove, false);
133-
if ((!classesAdded && !classesRemoved) || postDigestElements.length > 1) return;
134134

135+
// If we didn't change anything or if the handler has been added already
136+
// then don't add the handler now
137+
if (handlerAdded || (!classesAdded && !classesRemoved)) return;
138+
139+
handlerAdded = true;
135140
$rootScope.$$postDigest(function() {
136141
forEach(postDigestElements, function(element) {
137142
var data = postDigestQueue.get(element);
@@ -158,6 +163,7 @@ var $$CoreAnimateQueueProvider = function() {
158163
}
159164
});
160165

166+
handlerAdded = false;
161167
postDigestElements.length = 0;
162168
});
163169
}

test/ng/animateSpec.js

+15
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,21 @@ describe("$animate", function() {
341341
});
342342
});
343343

344+
345+
it('should not break postDigest for subsequent elements if addClass contains non-valid CSS class names', function() {
346+
inject(function($animate, $rootScope, $rootElement) {
347+
var element1 = jqLite('<div></div>');
348+
var element2 = jqLite('<div></div>');
349+
350+
$animate.enter(element1, $rootElement, null, { addClass: ' ' });
351+
$animate.enter(element2, $rootElement, null, { addClass: 'valid-name' });
352+
$rootScope.$digest();
353+
354+
expect(element2.hasClass('valid-name')).toBeTruthy();
355+
});
356+
});
357+
358+
344359
it('should not issue a call to removeClass if the provided class value is not a string or array', function() {
345360
inject(function($animate, $rootScope, $rootElement) {
346361
var spy = spyOn(window, 'jqLiteRemoveClass').andCallThrough();

0 commit comments

Comments
 (0)