From 2d3057944fe39587da47df99d62363f13198881c Mon Sep 17 00:00:00 2001 From: Max Date: Sat, 18 Nov 2017 14:41:58 -0600 Subject: [PATCH 1/2] Fix: correctly parsing echo with default="" --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index bc328bf..e47530b 100755 --- a/index.js +++ b/index.js @@ -27,7 +27,7 @@ var async = require('async'); var syntaxReg = //mg; var includeFileReg = //; var setVarReg = //; -var echoReg = //; +var echoReg = //; var ifReg = //; var elifReg = //; var elseReg = //; From 119231553fd3595f7f8589bbc8d8759aa411dff6 Mon Sep 17 00:00:00 2001 From: Max Date: Sat, 18 Nov 2017 14:43:18 -0600 Subject: [PATCH 2/2] Implemented a limited form of variable substitution in 'include' --- index.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index e47530b..c92d9a3 100755 --- a/index.js +++ b/index.js @@ -111,7 +111,7 @@ function resolve(tpl) { fnStr += '};\nreturn _r;'; - return new Function('__data', fnStr); + return new Function('__data', fnStr); } /** @@ -197,15 +197,22 @@ SSI.prototype = { * @param callback */ resolveIncludes: function(content, options, callback) { - var matches, seg, isVirtual, basePath, tpath, subOptions, ssi = this; + var matches, seg, isVirtual, basePath, tpath, subOptions, target, ssi = this; async.whilst( // https://www.npmjs.org/package/async#whilst-test-fn-callback- function test() {return !!(matches = includeFileReg.exec(content)); }, function insertInclude(next) { - seg = matches[0]; isVirtual = RegExp.$1 == 'virtual'; - basePath = (isVirtual && options.dirname && RegExp.$3.charAt(0) !== '/')? options.dirname : options.baseDir; - tpath = path.join(basePath, RegExp.$3); + target = RegExp.$3.replace( + /\$(?:\{([^}]+)\}|(\w+))/g, + function( _, m1, m2 ) { + return options.payload[m1||m2] || "" + } + ); + + seg = matches[0]; + basePath = (isVirtual && options.dirname && target.charAt(0) !== '/')? options.dirname : options.baseDir; + tpath = path.join(basePath, target); fs.lstat(tpath, function(err, stats) { if (err) {