From 7d6a56babcd1b0454fdb28d8eb636957b3cff9fa Mon Sep 17 00:00:00 2001 From: Dave Loose Date: Mon, 3 Oct 2016 21:47:07 -0400 Subject: [PATCH] fixed array escaping --- lib/create.js | 10 +++------- lib/util.js | 18 +++++++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/create.js b/lib/create.js index 33ac2dd..c7c295e 100644 --- a/lib/create.js +++ b/lib/create.js @@ -17,18 +17,14 @@ exports.create = function(queryArr, escape) { if (util.isString(q)) return s + q; if (util.isObject(args[0]) && !util.isArray(args[0])) { // direct mapping - val = util.wrap(args[0][q.name]); + val = util.wrap(args[0][q.name], escape); } else { // one at a time - val = util.wrap(args[q.idx]); + val = util.wrap(args[q.idx], escape); } if (_.isUndefined(val)) val = null; - if (_.isFunction(escape)) { - return s + escape(val); - } else { - return s + val; - } + return s + val; }, ''); }; }; diff --git a/lib/util.js b/lib/util.js index 9404f3f..d006458 100644 --- a/lib/util.js +++ b/lib/util.js @@ -43,17 +43,21 @@ module.exports = { read: function(path) { return fs.readFileSync(path, { encoding: 'utf8' }); }, - wrap: function(value) { - var wrapQuotes = function(v) { - if (_.isString(v)) return '"' + v + '"'; - return v; - }; + wrapQuotes: function (v) { + if (_.isString(v)) return '"' + v + '"'; + return v; + }, + + wrap: function (value, escape) { + if(!escape) { + escape = this.wrapQuotes; + } if (this.isString(value)) { - return wrapQuotes(value); + return escape(value); } else if (this.isArray(value)) { - return '(' + _.map(value, wrapQuotes).toString() + ')'; + return '(' + _.map(value, v => this.wrap(v, escape)).toString() + ')'; } else { return value; }