This repository was archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27.4k
fix($animate): improve detection and handling of invalid classNameFilter
RegExp
#14913
Closed
gkalpak
wants to merge
4
commits into
angular:master
from
gkalpak:fix-animate-invalid-classNameFilter
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
8cdd7bd
fix($animate): improve detection on `ng-animate` in `classNameFilter`…
gkalpak 5bf4ab0
fix($animate): reset `classNameFilter` to `null` when a disallowed Re…
gkalpak 899c52e
fixup! fix($animate): improve detection on `ng-animate` in `className…
gkalpak 7f0b72f
fixup! fix($animate): reset `classNameFilter` to `null` when a disall…
gkalpak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
@ngdoc error | ||
@name $animate:nongcls | ||
@fullName `ng-animate` class not allowed | ||
@description | ||
|
||
This error occurs, when trying to set `$animateProvider.classNameFilter()` to a RegExp containing | ||
the reserved `ng-animate` class. Since `.ng-animate` will be added/removed by `$animate` itself, | ||
using it as part of the `classNameFilter` RegExp is not allowed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -179,6 +179,7 @@ var $$CoreAnimateQueueProvider = /** @this */ function() { | |
*/ | ||
var $AnimateProvider = ['$provide', /** @this */ function($provide) { | ||
var provider = this; | ||
var classNameFilter = null; | ||
|
||
this.$$registeredAnimations = Object.create(null); | ||
|
||
|
@@ -247,15 +248,16 @@ var $AnimateProvider = ['$provide', /** @this */ function($provide) { | |
*/ | ||
this.classNameFilter = function(expression) { | ||
if (arguments.length === 1) { | ||
this.$$classNameFilter = (expression instanceof RegExp) ? expression : null; | ||
if (this.$$classNameFilter) { | ||
var reservedRegex = new RegExp('(\\s+|\\/)' + NG_ANIMATE_CLASSNAME + '(\\s+|\\/)'); | ||
if (reservedRegex.test(this.$$classNameFilter.toString())) { | ||
throw $animateMinErr('nongcls','$animateProvider.classNameFilter(regex) prohibits accepting a regex value which matches/contains the "{0}" CSS class.', NG_ANIMATE_CLASSNAME); | ||
classNameFilter = (expression instanceof RegExp) ? expression : null; | ||
if (classNameFilter) { | ||
var reservedRegex = new RegExp('[(\\s|\\/)]' + NG_ANIMATE_CLASSNAME + '[(\\s|\\/)]'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Btw, sneakiest change I've done to a RegExp ever 😈 |
||
if (reservedRegex.test(classNameFilter.toString())) { | ||
classNameFilter = null; | ||
throw $animateMinErr('nongcls', '$animateProvider.classNameFilter(regex) prohibits accepting a regex value which matches/contains the "{0}" CSS class.', NG_ANIMATE_CLASSNAME); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The error doesn't actually have an error page, can you add it? |
||
} | ||
} | ||
} | ||
return this.$$classNameFilter; | ||
return classNameFilter; | ||
}; | ||
|
||
this.$get = ['$$animateQueue', function($$animateQueue) { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
surely we should be throwing an error here, not silently ignoring invalid expressions??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not about ignoring invalid expressions (in the sense that they are of the wrong type).
This check is throwing when using
ng-animate
in your (valid) RegExp, sinceng-animate
is added by Angular itself.Not sure why this is important tbh. (Off the top of my head,
.ng-animate
will be added after theclassNameFilter()
but I might be wrong.)