From daa8428b32e2aa96d5253ecaf0c7f77eb2c946d2 Mon Sep 17 00:00:00 2001 From: jdalton Date: Mon, 25 May 2015 09:36:46 -0700 Subject: [PATCH] Drop `parseFloat` in `isIndex` in favor of a more strict regex. [closes #1229] --- lodash.src.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lodash.src.js b/lodash.src.js index c01e01765..506147494 100644 --- a/lodash.src.js +++ b/lodash.src.js @@ -117,6 +117,9 @@ /** Used to detect host constructors (Safari > 5). */ var reIsHostCtor = /^\[object .+?Constructor\]$/; + /** Used to detect unsigned integer values. */ + var reIsUint = /^\d+$/; + /** Used to match latin-1 supplementary letters (excluding mathematical operators). */ var reLatin1 = /[\xc0-\xd6\xd8-\xde\xdf-\xf6\xf8-\xff]/g; @@ -4221,7 +4224,7 @@ * @returns {boolean} Returns `true` if `value` is a valid index, else `false`. */ function isIndex(value, length) { - value = typeof value == 'number' ? value : parseFloat(value); + value = (typeof value == 'number' || reIsUint.test(value)) ? +value : NaN; length = length == null ? MAX_SAFE_INTEGER : length; return value > -1 && value % 1 == 0 && value < length; }