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 2021/11/23 10:00:50 UTC
[couchdb-nano] branch main updated: Properly escape partition ID's (fixes #283) (#284)
This is an automated email from the ASF dual-hosted git repository.
glynnbird pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/couchdb-nano.git
The following commit(s) were added to refs/heads/main by this push:
new cd650be Properly escape partition ID's (fixes #283) (#284)
cd650be is described below
commit cd650be42299596d377bcfc7fa7271b2104fd77a
Author: William Swanson <sw...@yahoo.com>
AuthorDate: Tue Nov 23 02:00:43 2021 -0800
Properly escape partition ID's (fixes #283) (#284)
This is a breaking change, for reasons descibed in that bug report.
---
lib/nano.js | 18 +++++++++---------
test/partition.list.test.js | 17 +++++++++++++++++
2 files changed, 26 insertions(+), 9 deletions(-)
diff --git a/lib/nano.js b/lib/nano.js
index 0b819ea..969248f 100644
--- a/lib/nano.js
+++ b/lib/nano.js
@@ -1036,7 +1036,7 @@ module.exports = exports = function dbScope (cfg) {
return relax({
db: dbName,
- path: '_partition/' + partitionKey
+ path: '_partition/' + encodeURIComponent(partitionKey)
}, callback)
}
@@ -1047,7 +1047,7 @@ module.exports = exports = function dbScope (cfg) {
}
return relax({
db: dbName,
- path: '_partition/' + partitionKey + '/_all_docs',
+ path: '_partition/' + encodeURIComponent(partitionKey) + '/_all_docs',
qs: opts
}, callback)
}
@@ -1055,7 +1055,7 @@ module.exports = exports = function dbScope (cfg) {
function partitionedListAsStream (partitionKey, qs) {
return relax({
db: dbName,
- path: '_partition/' + partitionKey + '/_all_docs',
+ path: '_partition/' + encodeURIComponent(partitionKey) + '/_all_docs',
qs: qs,
stream: true
})
@@ -1068,7 +1068,7 @@ module.exports = exports = function dbScope (cfg) {
return relax({
db: dbName,
- path: '_partition/' + partition + '/_find',
+ path: '_partition/' + encodeURIComponent(partition) + '/_find',
method: 'POST',
body: query
}, callback)
@@ -1077,7 +1077,7 @@ module.exports = exports = function dbScope (cfg) {
function partitionedFindAsStream (partition, query) {
return relax({
db: dbName,
- path: '_partition/' + partition + '/_find',
+ path: '_partition/' + encodeURIComponent(partition) + '/_find',
method: 'POST',
body: query,
stream: true
@@ -1090,7 +1090,7 @@ module.exports = exports = function dbScope (cfg) {
}
return relax({
db: dbName,
- path: '_partition/' + partition + '/_design/' + ddoc + '/_search/' + searchName,
+ path: '_partition/' + encodeURIComponent(partition) + '/_design/' + ddoc + '/_search/' + searchName,
qs: opts
}, callback)
}
@@ -1098,7 +1098,7 @@ module.exports = exports = function dbScope (cfg) {
function partitionedSearchAsStream (partition, ddoc, searchName, opts) {
return relax({
db: dbName,
- path: '_partition/' + partition + '/_design/' + ddoc + '/_search/' + searchName,
+ path: '_partition/' + encodeURIComponent(partition) + '/_design/' + ddoc + '/_search/' + searchName,
qs: opts,
stream: true
})
@@ -1110,7 +1110,7 @@ module.exports = exports = function dbScope (cfg) {
}
return relax({
db: dbName,
- path: '_partition/' + partition + '/_design/' + ddoc + '/_view/' + viewName,
+ path: '_partition/' + encodeURIComponent(partition) + '/_design/' + ddoc + '/_view/' + viewName,
qs: opts
}, callback)
}
@@ -1118,7 +1118,7 @@ module.exports = exports = function dbScope (cfg) {
function partitionedViewAsStream (partition, ddoc, viewName, opts) {
return relax({
db: dbName,
- path: '_partition/' + partition + '/_design/' + ddoc + '/_view/' + viewName,
+ path: '_partition/' + encodeURIComponent(partition) + '/_design/' + ddoc + '/_view/' + viewName,
qs: opts,
stream: true
})
diff --git a/test/partition.list.test.js b/test/partition.list.test.js
index 2d1035a..6e97071 100644
--- a/test/partition.list.test.js
+++ b/test/partition.list.test.js
@@ -121,6 +121,23 @@ test('should be able to list partition docs (callback) - GET /db/_partition/_all
})
})
+test('should escape unusual characters - GET /db/_partition/a+b/_all_docs - db.partitionedList', async () => {
+ // mocks
+ const scope = nock(COUCH_URL)
+ .get('/db/_partition/a%2Bb/_all_docs')
+ .reply(200, response)
+
+ // test GET /db/_partition/_all_docs
+ return new Promise((resolve, reject) => {
+ db.partitionedList('a+b', (err, data) => {
+ expect(err).toBeNull()
+ expect(data).toStrictEqual(response)
+ expect(scope.isDone()).toBe(true)
+ resolve()
+ })
+ })
+})
+
test('should handle missing database - GET /db/_partition/_all_docs - db.partitionedList', async () => {
// mocks
const scope = nock(COUCH_URL)