From 89da42d4a5888217b967dde6cbf2a1cde78862c4 Mon Sep 17 00:00:00 2001 From: Martin Date: Sun, 19 Jun 2016 21:41:09 +0500 Subject: [PATCH] fix(config.get): process intermediate templates in path --- lib/grunt/config.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/grunt/config.js b/lib/grunt/config.js index ef2bf8094..8249a2e3b 100644 --- a/lib/grunt/config.js +++ b/lib/grunt/config.js @@ -43,7 +43,28 @@ var propStringTmplRe = /^<%=\s*([a-z0-9_$]+(?:\.[a-z0-9_$]+)*)\s*%>$/i; // Get config data, recursively processing templates. config.get = function(prop) { - return config.process(config.getRaw(prop)); + var props = getParts(config.getPropString(prop)); + var currentData = config.data; + // from https://github.com/cowboy/node-getobject/blob/master/lib/getobject.js + // Split strings on dot, but only if dot isn't preceded by a backslash. Since + // JavaScript doesn't support lookbehinds, use a placeholder for "\.", split + // on dot, then replace the placeholder character with a dot. + function getParts(str) { + return str.replace(/\\\./g, '\uffff').split('.').map(function(s) { + return s.replace(/\uffff/g, '.'); + }); + } + + props.forEach(function(item) { + currentData = currentData[item]; + // if current value is template -- expand it + if (typeof currentData === 'string' && + currentData.match(propStringTmplRe)) { + currentData = config.process(currentData); + } + }); + + return config.process(currentData); }; // Expand a config value recursively. Used for post-processing raw values