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

Commit 8cdd7bd

Browse files
committed
fix($animate): improve detection on ng-animate in classNameFilter RegExp
1 parent 4e143fc commit 8cdd7bd

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

src/ng/animate.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ var $$CoreAnimateQueueProvider = /** @this */ function() {
179179
*/
180180
var $AnimateProvider = ['$provide', /** @this */ function($provide) {
181181
var provider = this;
182+
var classNameFilter = null;
182183

183184
this.$$registeredAnimations = Object.create(null);
184185

@@ -247,15 +248,15 @@ var $AnimateProvider = ['$provide', /** @this */ function($provide) {
247248
*/
248249
this.classNameFilter = function(expression) {
249250
if (arguments.length === 1) {
250-
this.$$classNameFilter = (expression instanceof RegExp) ? expression : null;
251-
if (this.$$classNameFilter) {
252-
var reservedRegex = new RegExp('(\\s+|\\/)' + NG_ANIMATE_CLASSNAME + '(\\s+|\\/)');
253-
if (reservedRegex.test(this.$$classNameFilter.toString())) {
254-
throw $animateMinErr('nongcls','$animateProvider.classNameFilter(regex) prohibits accepting a regex value which matches/contains the "{0}" CSS class.', NG_ANIMATE_CLASSNAME);
251+
classNameFilter = (expression instanceof RegExp) ? expression : null;
252+
if (classNameFilter) {
253+
var reservedRegex = new RegExp('[(\\s|\\/)]' + NG_ANIMATE_CLASSNAME + '[(\\s|\\/)]');
254+
if (reservedRegex.test(classNameFilter.toString())) {
255+
throw $animateMinErr('nongcls', '$animateProvider.classNameFilter(regex) prohibits accepting a regex value which matches/contains the "{0}" CSS class.', NG_ANIMATE_CLASSNAME);
255256
}
256257
}
257258
}
258-
return this.$$classNameFilter;
259+
return classNameFilter;
259260
};
260261

261262
this.$get = ['$$animateQueue', function($$animateQueue) {

test/ngAnimate/animateSpec.js

+11-7
Original file line numberDiff line numberDiff line change
@@ -255,29 +255,33 @@ 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-
273277
if (bool) {
274-
expectation.toThrowMinErr('$animate', 'nongcls', message);
278+
expectation.toThrowMinErr('$animate', 'nongcls', errorMessage);
275279
} else {
276-
expectation.not.toThrowMinErr('$animate', 'nongcls', message);
280+
expectation.not.toThrow();
277281
}
278282
}
279-
});
280-
});
283+
})
284+
);
281285

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

0 commit comments

Comments
 (0)