From 70c9802d014c45e0e301e6683e64626a38b1a8bd Mon Sep 17 00:00:00 2001 From: anseki Date: Sat, 18 Jul 2015 14:39:24 +0900 Subject: [PATCH] Fix: getDeepPropFromObj does not work --- lib/preprocess.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/preprocess.js b/lib/preprocess.js index 1d10bd7..09875ed 100644 --- a/lib/preprocess.js +++ b/lib/preprocess.js @@ -392,16 +392,21 @@ function copy(obj) { } function getDeepPropFromObj(obj, propPath) { - propPath.replace(/\[([^\]+?])\]/g, '.$1'); - propPath = propPath.split('.'); + var propPathList = []; + propPath = propPath.replace(/(.*?)(?:\[(.+?)\]|\.)/g, function(s, prev, prop) { + if (prev) { propPathList.push(prev); } + if (prop) { propPathList.push(prop); } + return ''; + }); + if (propPath) { propPathList.push(propPath); } // fast path, no need to loop if structurePath contains only a single segment - if (propPath.length === 1) { - return obj[propPath[0]]; + if (propPathList.length === 1) { + return obj[propPathList[0]]; } // loop only as long as possible (no exceptions for null/undefined property access) - propPath.some(function (pathSegment) { + propPathList.some(function (pathSegment) { obj = obj[pathSegment]; return (obj == null); });