Skip to content

Commit

Permalink
changed toQuery() to whitelist parameters to be JSON encoded
Browse files Browse the repository at this point in the history
  • Loading branch information
zdzolton authored and felixge committed Apr 7, 2010
1 parent d4af805 commit d43a67a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions lib/couchdb.js
Expand Up @@ -77,11 +77,13 @@ exports.toJSON = function(data) {
});
};

// Encode query values to JSON except the stale parameter
// Encode only key, startkey and endkey as JSON
exports.toQuery = function(query) {
for (var k in query) {
if (k !== 'stale') {
if (['key', 'startkey', 'endkey'].indexOf(k) != -1) {
query[k] = JSON.stringify(query[k]);
} else {
query[k] = String(query[k]);
}
}
return querystring.stringify(query);
Expand Down
4 changes: 2 additions & 2 deletions test/test-to-query.js
@@ -1,8 +1,8 @@
require('./common');

var query = couchdb.toQuery({
foo: 'bar',
key: 'bar',
very: true,
stale: 'ok'
});
assert.equal('foo=%22bar%22&very=true&stale=ok', query);
assert.equal('key=%22bar%22&very=true&stale=ok', query);

0 comments on commit d43a67a

Please sign in to comment.