Skip to content

Commit 124c5fd

Browse files
authored
Merge pull request #111 from bestlong/fix-no-mustache
Fix ineffective `parseMustache` option
2 parents aa42381 + 8773a7d commit 124c5fd

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/mssql.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -416,11 +416,11 @@ <h3>Shameless request for beta testers...</h3>
416416
return this.name ? 'node_label_italic' : '';
417417
},
418418
oneditprepare: function () {
419-
if (this.parseMustache === undefined) {
420-
this.parseMustache = true;
419+
const node = this;
420+
if (typeof node.parseMustache === 'undefined') {
421+
node.parseMustache = true;
421422
$('#node-input-parseMustache').prop('checked', true);
422423
}
423-
const node = this;
424424
//ensure node.query is a string otherwise editor wont initialise
425425
if (typeof node.query !== 'string') node.query = '';
426426
//create the query editor

src/mssql.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ module.exports = function (RED) {
335335
// node-mssql 5.x to 6.x changes
336336
// ConnectionPool.close() now returns a promise / callbacks will be executed once closing of the
337337
if (node.pool && node.pool.close) {
338-
node.pool.close().catch(() => {})
338+
node.pool.close().catch(() => {});
339339
}
340340
if (updateStatusAndLog) node.status({ fill: 'grey', shape: 'dot', text: 'disconnected' });
341341
node.poolConnect = null;
@@ -496,7 +496,7 @@ module.exports = function (RED) {
496496
node.paramsOptType = config.paramsOptType || 'none';
497497
node.rows = config.rows || 'rows';
498498
node.rowsType = config.rowsType || 'msg';
499-
node.parseMustache = config.parseMustache || true;
499+
node.parseMustache = !(config.parseMustache === false || config.parseMustache === 'false'); // if not explicitly set to false, then enable mustache parsing
500500

501501
const setResult = function (msg, field, value, returnType = 0) {
502502
// eslint-disable-next-line eqeqeq
@@ -752,10 +752,11 @@ module.exports = function (RED) {
752752
}
753753
}
754754

755+
const promises = [];
756+
const resolvedTokens = {};
757+
let tokens;
755758
if (node.parseMustache) {
756-
const promises = [];
757-
const tokens = extractTokens(mustache.parse(msg.query));
758-
const resolvedTokens = {};
759+
tokens = extractTokens(mustache.parse(msg.query));
759760
tokens.forEach(function (name) {
760761
const envName = parseEnv(name);
761762
if (envName) {
@@ -789,7 +790,8 @@ module.exports = function (RED) {
789790
}
790791
}
791792
});
792-
793+
}
794+
if (tokens && tokens.size > 0) {
793795
Promise.all(promises).then(function () {
794796
const value = mustache.render(msg.query, new NodeContext(msg, node.context(), null, false, resolvedTokens));
795797
msg.query = value;

0 commit comments

Comments
 (0)