You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by gl...@apache.org on 2018/07/02 14:03:23 UTC
[couchdb-nano] branch master updated: clone user-supplied query
string object prior to mutation - issue #85 (#95)
This is an automated email from the ASF dual-hosted git repository.
glynnbird pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/couchdb-nano.git
The following commit(s) were added to refs/heads/master by this push:
new 85136e9 clone user-supplied query string object prior to mutation - issue #85 (#95)
85136e9 is described below
commit 85136e9e623569bf406a3f865f68220435552fa7
Author: Glynn Bird <gl...@gmail.com>
AuthorDate: Mon Jul 2 15:03:21 2018 +0100
clone user-supplied query string object prior to mutation - issue #85 (#95)
* clone use-supplied query string object prior to mutation - fixes issue #85
* use Object.assign to clone object
* save line of code and qs->qs1
---
lib/nano.js | 24 +++++++++++++-----------
1 file changed, 13 insertions(+), 11 deletions(-)
diff --git a/lib/nano.js b/lib/nano.js
index 0ea96de..84d2a32 100644
--- a/lib/nano.js
+++ b/lib/nano.js
@@ -557,7 +557,9 @@ module.exports = exports = nano = function dbScope(cfg) {
callback = qs;
qs = {};
}
- qs = qs || {};
+
+ // prevent mutation of the client qs object by using a clone
+ var qs1 = Object.assign({}, qs)
var viewPath = '_design/' + ddoc + '/_' + meta.type + '/' + viewName;
@@ -565,28 +567,28 @@ module.exports = exports = nano = function dbScope(cfg) {
// object API, several parameters need JSON endoding.
var paramsToEncode = ['counts', 'drilldown', 'group_sort', 'ranges', 'sort'];
paramsToEncode.forEach(function(param) {
- if (param in qs) {
- if (typeof qs[param] !== 'string') {
- qs[param] = JSON.stringify(qs[param]);
+ if (param in qs1) {
+ if (typeof qs1[param] !== 'string') {
+ qs1[param] = JSON.stringify(qs1[param]);
} else {
// if the parameter is not already encoded, encode it
try {
- JSON.parse(qs[param]);
+ JSON.parse(qs1[param]);
} catch(e) {
- qs[param] = JSON.stringify(qs[param]);
+ qs1[param] = JSON.stringify(qs1[param]);
}
}
}
});
- if (qs && qs.keys) {
- var body = {keys: qs.keys};
- delete qs.keys;
+ if (qs1 && qs1.keys) {
+ var body = {keys: qs1.keys};
+ delete qs1.keys;
return relax({
db: dbName,
path: viewPath,
method: 'POST',
- qs: qs,
+ qs: qs1,
body: body
}, callback);
} else {
@@ -594,7 +596,7 @@ module.exports = exports = nano = function dbScope(cfg) {
db: dbName,
method: meta.method || 'GET',
path: viewPath,
- qs: qs
+ qs: qs1
};
if (meta.body) {