-
Notifications
You must be signed in to change notification settings - Fork 27.4k
fix(filter): Don't throw key.charAt is not a function
when object's keys are not of type string
.
#15660
Conversation
key.charAt is not a function
when object's keys are not of type string
.key.charAt is not a function
when object's keys are not of type string
.
… keys are not of type `string`. Previously, when an object has keys which are not of type string, the `filter` would throw an exception for trying to call `charAt`, which is not defined on a none-string type. This commit checks whether `charAt` is defined before calling it. Closes #15644
Can you please add a test for this? |
I am afraid it is not possible (as discussed in #15644) 😁 Unless we messed with the |
src/ng/filter/filter.js
Outdated
@@ -226,7 +226,7 @@ function deepCompare(actual, expected, comparator, anyPropertyKey, matchAgainstA | |||
var key; | |||
if (matchAgainstAnyProp) { | |||
for (key in actual) { | |||
if ((key.charAt(0) !== '$') && deepCompare(actual[key], expected, comparator, anyPropertyKey, true)) { | |||
if (key.charAt && (key.charAt(0) !== '$') && deepCompare(actual[key], expected, comparator, anyPropertyKey, true)) { |
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.
Add a comment (and maybe a link to the issue) for context. Something like:
Under certain, extreme circumstances,
key
may not be a string. See ...`
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.
I've added some comment.
…bject's keys are not of type `string`.
LGTM if it LGT @Narretz 😃 |
LGTM |
Previously, when an object has keys which are not of type string, `filterFilter` would throw an exception for trying to call `key.charAt()`, which is a string method. This commit checks whether `charAt` is defined before calling it. Fixes angular#15644 Closes angular#15660
What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
Bug fix
What is the current behavior? (You can also link to an open issue here)
When an object has keys which are not of type string, the
filter
would throw an exception for trying to callcharAt
, which is not defined on a none-string type.#15644
What is the new behavior (if this is a feature change)?
This commit checks whether
charAt
is defined before calling it.Does this PR introduce a breaking change?
No
Please check if the PR fulfills these requirements
Other information: