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

Commit 182b65c

Browse files
committed
fix($animate): silently ignore the options param if an object is not passed in
Earlier versions of Angular expected a function to be passed into the same param as the options value. This causes a nasty issue since the internal animation code expects the options value to be an object instead of a function. This patch adds the code to convert a function value into an empty object when that occurs. Closes #11713
1 parent b2ae35c commit 182b65c

File tree

2 files changed

+59
-4
lines changed

2 files changed

+59
-4
lines changed

src/ng/animate.js

+11-4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ function mergeClasses(a,b) {
1212
return a + ' ' + b;
1313
}
1414

15+
function makeAnimateOptions(options) {
16+
return isObject(options) ? options : {};
17+
}
18+
1519
function extractElementNode(element) {
1620
for (var i = 0; i < element.length; i++) {
1721
var elm = element[i];
@@ -406,6 +410,7 @@ var $AnimateProvider = ['$provide', function($provide) {
406410
* @return {Promise} the animation callback promise
407411
*/
408412
enter: function(element, parent, after, options) {
413+
options = makeAnimateOptions(options);
409414
parent = parent || after.parent();
410415
domInsert(element, parent, after);
411416
return $$animateQueue.push(element, 'enter', options);
@@ -430,6 +435,7 @@ var $AnimateProvider = ['$provide', function($provide) {
430435
* @return {Promise} the animation callback promise
431436
*/
432437
move: function(element, parent, after, options) {
438+
options = makeAnimateOptions(options);
433439
parent = parent || after.parent();
434440
domInsert(element, parent, after);
435441
return $$animateQueue.push(element, 'move', options);
@@ -449,6 +455,7 @@ var $AnimateProvider = ['$provide', function($provide) {
449455
* @return {Promise} the animation callback promise
450456
*/
451457
leave: function(element, options) {
458+
options = makeAnimateOptions(options);
452459
return $$animateQueue.push(element, 'leave', options, function() {
453460
element.remove();
454461
});
@@ -473,7 +480,7 @@ var $AnimateProvider = ['$provide', function($provide) {
473480
* @return {Promise} the animation callback promise
474481
*/
475482
addClass: function(element, className, options) {
476-
options = options || {};
483+
options = makeAnimateOptions(options);
477484
options.addClass = mergeClasses(options.addclass, className);
478485
return $$animateQueue.push(element, 'addClass', options);
479486
},
@@ -497,7 +504,7 @@ var $AnimateProvider = ['$provide', function($provide) {
497504
* @return {Promise} the animation callback promise
498505
*/
499506
removeClass: function(element, className, options) {
500-
options = options || {};
507+
options = makeAnimateOptions(options);
501508
options.removeClass = mergeClasses(options.removeClass, className);
502509
return $$animateQueue.push(element, 'removeClass', options);
503510
},
@@ -522,7 +529,7 @@ var $AnimateProvider = ['$provide', function($provide) {
522529
* @return {Promise} the animation callback promise
523530
*/
524531
setClass: function(element, add, remove, options) {
525-
options = options || {};
532+
options = makeAnimateOptions(options);
526533
options.addClass = mergeClasses(options.addClass, add);
527534
options.removeClass = mergeClasses(options.removeClass, remove);
528535
return $$animateQueue.push(element, 'setClass', options);
@@ -550,7 +557,7 @@ var $AnimateProvider = ['$provide', function($provide) {
550557
* @return {Promise} the animation callback promise
551558
*/
552559
animate: function(element, from, to, className, options) {
553-
options = options || {};
560+
options = makeAnimateOptions(options);
554561
options.from = options.from ? extend(options.from, from) : from;
555562
options.to = options.to ? extend(options.to, to) : to;
556563

test/ngAnimate/animateSpec.js

+48
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,54 @@ describe("animations", function() {
486486
});
487487
});
488488

489+
they('$prop() shouldn\'t blow up when a function is passed as the options param',
490+
['enter', 'move', 'leave', 'addClass', 'removeClass', 'setClass', 'animate'], function(event) {
491+
492+
inject(function($animate, $rootScope, $document) {
493+
var element = $document[0].createElement('div');
494+
element.setAttribute('id', 'crazy-man');
495+
if (event !== 'enter' && event !== 'move') {
496+
parent.append(element);
497+
}
498+
499+
var fakeOption = function() { };
500+
501+
switch (event) {
502+
case 'enter':
503+
case 'move':
504+
$animate[event](element, parent, parent2, fakeOption);
505+
break;
506+
507+
case 'addClass':
508+
$animate.addClass(element, 'klass', fakeOption);
509+
break;
510+
511+
case 'removeClass':
512+
element.className = 'klass';
513+
$animate.removeClass(element, 'klass', fakeOption);
514+
break;
515+
516+
case 'setClass':
517+
element.className = 'two';
518+
$animate.setClass(element, 'one', 'two', fakeOption);
519+
break;
520+
521+
case 'leave':
522+
$animate.leave(element, fakeOption);
523+
break;
524+
525+
case 'animate':
526+
var toStyles = { color: 'red' };
527+
$animate.animate(element, {}, toStyles, 'klass', fakeOption);
528+
break;
529+
}
530+
531+
$rootScope.$digest();
532+
var options = capturedAnimation[2];
533+
expect(isObject(options)).toBeTruthy();
534+
});
535+
})
536+
489537
describe('addClass / removeClass', function() {
490538
it('should not perform an animation if there are no valid CSS classes to add',
491539
inject(function($animate, $rootScope) {

0 commit comments

Comments
 (0)