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

Commit 012319d

Browse files
committed
fix($animate): improve detection on ng-animate in classNameFilter RegExp
1 parent aea62af commit 012319d

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

src/ng/animate.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ var $$CoreAnimateQueueProvider = function() {
169169
*/
170170
var $AnimateProvider = ['$provide', function($provide) {
171171
var provider = this;
172+
var classNameFilter = null;
172173

173174
this.$$registeredAnimations = Object.create(null);
174175

@@ -237,16 +238,15 @@ var $AnimateProvider = ['$provide', function($provide) {
237238
*/
238239
this.classNameFilter = function(expression) {
239240
if (arguments.length === 1) {
240-
this.$$classNameFilter = (expression instanceof RegExp) ? expression : null;
241-
if (this.$$classNameFilter) {
242-
var reservedRegex = new RegExp("(\\s+|\\/)" + NG_ANIMATE_CLASSNAME + "(\\s+|\\/)");
243-
if (reservedRegex.test(this.$$classNameFilter.toString())) {
244-
throw $animateMinErr('nongcls','$animateProvider.classNameFilter(regex) prohibits accepting a regex value which matches/contains the "{0}" CSS class.', NG_ANIMATE_CLASSNAME);
245-
241+
classNameFilter = (expression instanceof RegExp) ? expression : null;
242+
if (classNameFilter) {
243+
var reservedRegex = new RegExp('[(\\s|\\/)]' + NG_ANIMATE_CLASSNAME + '[(\\s|\\/)]');
244+
if (reservedRegex.test(classNameFilter.toString())) {
245+
throw $animateMinErr('nongcls', '$animateProvider.classNameFilter(regex) prohibits accepting a regex value which matches/contains the "{0}" CSS class.', NG_ANIMATE_CLASSNAME);
246246
}
247247
}
248248
}
249-
return this.$$classNameFilter;
249+
return classNameFilter;
250250
};
251251

252252
this.$get = ['$$animateQueue', function($$animateQueue) {
@@ -594,7 +594,7 @@ var $AnimateProvider = ['$provide', function($provide) {
594594
*
595595
* @description Performs an inline animation on the element which applies the provided to and from CSS styles to the element.
596596
* If any detected CSS transition, keyframe or JavaScript matches the provided className value, then the animation will take
597-
* on the provided styles. For example, if a transition animation is set for the given classNamem, then the provided `from` and
597+
* on the provided styles. For example, if a transition animation is set for the given className, then the provided `from` and
598598
* `to` styles will be applied alongside the given transition. If the CSS style provided in `from` does not have a corresponding
599599
* style in `to`, the style in `from` is applied immediately, and no animation is run.
600600
* If a JavaScript animation is detected then the provided styles will be given in as function parameters into the `animate`

test/ngAnimate/animateSpec.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -255,26 +255,30 @@ describe("animations", function() {
255255
});
256256
});
257257

258-
it('should throw a minErr if a regex value is used which partially contains or fully matches the `ng-animate` CSS class', function() {
258+
it('should throw a minErr if a regex value is used which partially contains or fully matches the `ng-animate` CSS class',
259259
module(function($animateProvider) {
260+
var errorMessage = '$animateProvider.classNameFilter(regex) prohibits accepting a regex ' +
261+
'value which matches/contains the "ng-animate" CSS class.';
262+
260263
assertError(/ng-animate/, true);
261264
assertError(/first ng-animate last/, true);
262265
assertError(/ng-animate-special/, false);
263266
assertError(/first ng-animate-special last/, false);
264267
assertError(/first ng-animate ng-animate-special last/, true);
268+
assertError(/(ng-animate)/, true);
269+
assertError(/(foo|ng-animate|bar)/, true);
270+
assertError(/(foo|)ng-animate(|bar)/, true);
265271

266272
function assertError(regex, bool) {
267273
var expectation = expect(function() {
268274
$animateProvider.classNameFilter(regex);
269275
});
270276

271-
var message = '$animateProvider.classNameFilter(regex) prohibits accepting a regex value which matches/contains the "ng-animate" CSS class.';
272-
273-
bool ? expectation.toThrowMinErr('$animate', 'nongcls', message)
274-
: expectation.not.toThrowMinErr('$animate', 'nongcls', message);
277+
bool ? expectation.toThrowMinErr('$animate', 'nongcls', errorMessage)
278+
: expectation.not.toThrow();
275279
}
276-
});
277-
});
280+
})
281+
);
278282

279283
it('should complete the leave DOM operation in case the classNameFilter fails', function() {
280284
module(function($animateProvider) {

0 commit comments

Comments
 (0)