This repository has been 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.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(isArrayLike): correctly handle string primitives
Closes #3356
- Loading branch information
Showing
2 changed files
with
12 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -87,22 +87,21 @@ if (isNaN(msie)) { | |
/** | ||
* @private | ||
* @param {*} obj | ||
* @return {boolean} Returns true if `obj` is an array or array-like object (NodeList, Arguments, ...) | ||
* @return {boolean} Returns true if `obj` is an array or array-like object (NodeList, Arguments, String ...) | ||
*/ | ||
function isArrayLike(obj) { | ||
if (obj == null || isWindow(obj)) { | ||
return false; | ||
} | ||
|
||
var length = obj.length; | ||
|
||
if (obj.nodeType === 1 && length) { | ||
return true; | ||
} | ||
|
||
return isArray(obj) || !isFunction(obj) && ( | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
btford
Contributor
|
||
length === 0 || typeof length === "number" && length > 0 && (length - 1) in obj | ||
); | ||
return isString(obj) || isArray(obj) || length === 0 || | ||
typeof length === 'number' && length > 0 && (length - 1) in obj; | ||
} | ||
|
||
/** | ||
|
@@ -599,7 +598,7 @@ function isLeafNode (node) { | |
* * If a destination is provided, all of its elements (for array) or properties (for objects) | ||
* are deleted and then all elements/properties from the source are copied to it. | ||
* * If `source` is not an object or array (inc. `null` and `undefined`), `source` is returned. | ||
* * If `source` is identical to 'destination' an exception will be thrown. | ||
* * If `source` is identical to 'destination' an exception will be thrown. | ||
* | ||
* Note: this function is used to augment the Object type in Angular expressions. See | ||
* {@link ng.$filter} for more information about Angular arrays. | ||
|
This file contains 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
@btford Since my original
typeof
guard didn't make it through, this!isFunction(object)
test should be kept!I propose this statement:
(exact same as before my PR, only adding
|| isString(obj)
)