diff --git a/lib/utils.js b/lib/utils.js index 651b7fff81607a60fe4b80e7e1b6009c23686b24..3123b4158c97b903d1e8583a271a8b700c323c39 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -130,6 +130,16 @@ function trim(str) { return str.replace(/^\s*/, '').replace(/\s*$/, ''); } +/** + * Determine if a value is an Arguments object + * + * @param {Object} val The value to test + * @returns {boolean} True if value is an Arguments object, otherwise false + */ +function isArguments(val) { + return toString.call(val) === '[object Arguments]'; +} + /** * Iterate over an Array or an Object invoking a function for each item. * @@ -149,7 +159,7 @@ function forEach(obj, fn) { } // Check if obj is array-like - var isArrayLike = isArray(obj) || (typeof obj === 'object' && !isNaN(obj.length)); + var isArrayLike = isArray(obj) || isArguments(obj); // Force an array if not already something iterable if (typeof obj !== 'object' && !isArrayLike) { diff --git a/test/specs/helpers/buildUrl.spec.js b/test/specs/helpers/buildUrl.spec.js index 4b4bd01e78b83f7a96e7606b4b82a31f3ba5eb4c..6bcaed03188b05276197ea7d86c43ddbc52ce319 100644 --- a/test/specs/helpers/buildUrl.spec.js +++ b/test/specs/helpers/buildUrl.spec.js @@ -44,5 +44,13 @@ describe('helpers::buildUrl', function () { bar: 'baz' })).toEqual('/foo?foo=bar&bar=baz'); }); + + it('should support "length" parameter', function () { + expect(buildUrl('/foo', { + query: 'bar', + start: 0, + length: 5 + })).toEqual('/foo?query=bar&start=0&length=5'); + }); });