Skip to content

Commit 4eb5100

Browse files
committed
fix(config.get): process intermediate templates in path
1 parent 662bd69 commit 4eb5100

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

lib/grunt/config.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,28 @@ var propStringTmplRe = /^<%=\s*([a-z0-9_$]+(?:\.[a-z0-9_$]+)*)\s*%>$/i;
4343

4444
// Get config data, recursively processing templates.
4545
config.get = function(prop) {
46-
return config.process(config.getRaw(prop));
46+
var props = getParts(config.getPropString(prop));
47+
var currentData = config.data;
48+
// from https://github.com/cowboy/node-getobject/blob/master/lib/getobject.js
49+
// Split strings on dot, but only if dot isn't preceded by a backslash. Since
50+
// JavaScript doesn't support lookbehinds, use a placeholder for "\.", split
51+
// on dot, then replace the placeholder character with a dot.
52+
function getParts(str) {
53+
return str.replace(/\\\./g, '\uffff').split('.').map(function(s) {
54+
return s.replace(/\uffff/g, '.');
55+
});
56+
}
57+
58+
props.forEach(function(item) {
59+
currentData = currentData[item];
60+
// if current value is template -- expand it
61+
if (typeof currentData === 'string' &&
62+
currentData.match(propStringTmplRe)) {
63+
currentData = config.process(currentData);
64+
}
65+
});
66+
67+
return config.process(currentData);
4768
};
4869

4970
// Expand a config value recursively. Used for post-processing raw values

0 commit comments

Comments
 (0)