Permalink
Browse files

Fixed couchdb.toQuery

All values need to be JSON encoded, except stale=ok
  • Loading branch information...
1 parent cb4d08b commit f02ba6fe74fd287f07e22d9e720874c634677905 @felixge felixge committed Mar 9, 2010
Showing with 11 additions and 3 deletions.
  1. +3 −3 lib/couchdb.js
  2. +8 −0 test/test-to-query.js
View
6 lib/couchdb.js
@@ -19,11 +19,11 @@ exports.toJSON = function(data) {
});
};
-// Use boolean strings since couch expects those
+// Encode query values to JSON except the stale parameter
exports.toQuery = function(query) {
for (var k in query) {
- if (typeof query[k] == 'boolean') {
- query[k] = String(query[k]);
+ if (k !== 'stale') {
+ query[k] = JSON.stringify(query[k]);
}
}
return querystring.stringify(query);
View
8 test/test-to-query.js
@@ -0,0 +1,8 @@
+require('./common');
+
+var query = couchdb.toQuery({
+ foo: 'bar',
+ very: true,
+ stale: 'ok'
+});
+assert.equal('foo=%22bar%22&very=true&stale=ok', query);

0 comments on commit f02ba6f

Please sign in to comment.