Skip to content

Commit 79c7b92

Browse files
committed
fix(isArrayLike): correctly handle string primitives
Closes angular#3356
1 parent 699f86c commit 79c7b92

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/Angular.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,12 @@ function isArrayLike(obj) {
9090
return true;
9191
}
9292

93-
return isArray(obj) || !isFunction(obj) && (
94-
length === 0 || typeof length === "number" && length > 0 && (length - 1) in obj
95-
);
93+
if (typeof obj !== 'object') {
94+
return typeof obj === 'string';
95+
}
96+
97+
return isArray(obj) || length === 0 ||
98+
typeof length === "number" && length > 0 && (length - 1) in obj;
9699
}
97100

98101
/**

test/AngularSpec.js

+7
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,13 @@ describe('angular', function() {
461461
expect(log).toEqual(['0:a', '1:b', '2:c']);
462462
});
463463

464+
it('should handle string values like arrays', function() {
465+
var log = [];
466+
467+
forEach('bar', function(value, key) { log.push(key + ':' + value)});
468+
expect(log).toEqual(['0:b', '1:a', '2:r']);
469+
});
470+
464471

465472
it('should handle objects with length property as objects', function() {
466473
var obj = {

0 commit comments

Comments
 (0)