Skip to content
This repository has been archived by the owner on Apr 13, 2022. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
fix($animate): invalid CSS class names should not break subsequent el…
…ements

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 #12674
Closes #12725
  • Loading branch information
petebacondarwin committed Sep 2, 2015
1 parent e7293da commit c3a654b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/ng/animate.js
Expand Up @@ -151,18 +151,20 @@ var $$CoreAnimateQueueProvider = function() {


function addRemoveClassesPostDigest(element, add, remove) {
var classVal, data = postDigestQueue.get(element);

if (!data) {
postDigestQueue.put(element, data = {});
postDigestElements.push(element);
}
var data = postDigestQueue.get(element) || {};

var classesAdded = updateData(data, add, true);
var classesRemoved = updateData(data, remove, false);
if ((!classesAdded && !classesRemoved) || postDigestElements.length > 1) return;

$rootScope.$$postDigest(handleCSSClassChanges);
if (classesAdded || classesRemoved) {

postDigestQueue.put(element, data);
postDigestElements.push(element);

if (postDigestElements.length === 1) {
$rootScope.$$postDigest(handleCSSClassChanges);
}
}
}
}];
};
Expand Down
15 changes: 15 additions & 0 deletions test/ng/animateSpec.js
Expand Up @@ -341,6 +341,21 @@ describe("$animate", function() {
});
});


it('should not break postDigest for subsequent elements if addClass contains non-valid CSS class names', function() {
inject(function($animate, $rootScope, $rootElement) {
var element1 = jqLite('<div></div>');
var element2 = jqLite('<div></div>');

$animate.enter(element1, $rootElement, null, { addClass: ' ' });
$animate.enter(element2, $rootElement, null, { addClass: 'valid-name' });
$rootScope.$digest();

expect(element2.hasClass('valid-name')).toBeTruthy();
});
});


it('should not issue a call to removeClass if the provided class value is not a string or array', function() {
inject(function($animate, $rootScope, $rootElement) {
var spy = spyOn(window, 'jqLiteRemoveClass').andCallThrough();
Expand Down

0 comments on commit c3a654b

Please sign in to comment.