From 5e38259044047c1a5f2e2e7010800872ed29a0f7 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Tue, 7 Feb 2017 10:48:46 -0800 Subject: [PATCH] Expand `stringToPath` to matching more non-string expressions. --- .internal/stringToPath.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/.internal/stringToPath.js b/.internal/stringToPath.js index 886fdec66..24fbd43a7 100644 --- a/.internal/stringToPath.js +++ b/.internal/stringToPath.js @@ -7,8 +7,8 @@ const rePropName = RegExp( '[^.[\\]]+' + '|' + // Or match property names within brackets. '\\[(?:' + - // Match numbers. - '(-?\\d+(?:\\.\\d+)?)' + '|' + + // Match a non-string expression. + '([^"\'].*)' + '|' + // Or match strings (supports escaping characters). '(["\'])((?:(?!\\2)[^\\\\]|\\\\.)*?)\\2' + ')\\]'+ '|' + @@ -28,8 +28,15 @@ const stringToPath = memoizeCapped(string => { if (reLeadingDot.test(string)) { result.push('') } - string.replace(rePropName, (match, number, quote, string) => { - result.push(quote ? string.replace(reEscapeChar, '$1') : (number || match)) + string.replace(rePropName, (match, expression, quote, string) => { + let key = match + if (quote) { + key = string.replace(reEscapeChar, '$1') + } + else if (expression) { + key = expression.trim() + } + result.push(key) }) return result })