Skip to content

Commit

Permalink
Properly escape input in the partitioned methods
Browse files Browse the repository at this point in the history
This is a fix for apache#283.

As discussed in that issue, this is probably a breaking change, and may need to wait for the next major version bump.

All the other API's in Nano escape their path components (database names, design documents, views, etc.), but for some reason these partitioned ones do not.
  • Loading branch information
swansontec authored Nov 18, 2021
1 parent 2d4bd71 commit ac7b770
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions lib/nano.js
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,7 @@ module.exports = exports = function dbScope (cfg) {

return relax({
db: dbName,
path: '_partition/' + partitionKey
path: '_partition/' + encodeURIComponent(partitionKey)
}, callback)
}

Expand All @@ -1047,15 +1047,15 @@ module.exports = exports = function dbScope (cfg) {
}
return relax({
db: dbName,
path: '_partition/' + partitionKey + '/_all_docs',
path: '_partition/' + encodeURIComponent(partitionKey) + '/_all_docs',
qs: opts
}, callback)
}

function partitionedListAsStream (partitionKey, qs) {
return relax({
db: dbName,
path: '_partition/' + partitionKey + '/_all_docs',
path: '_partition/' + encodeURIComponent(partitionKey) + '/_all_docs',
qs: qs,
stream: true
})
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -1090,15 +1090,15 @@ module.exports = exports = function dbScope (cfg) {
}
return relax({
db: dbName,
path: '_partition/' + partition + '/_design/' + ddoc + '/_search/' + searchName,
path: '_partition/' + encodeURIComponent(partition) + '/_design/' + encodeURIComponent(ddoc) + '/_search/' + encodeURIComponent(searchName),
qs: opts
}, callback)
}

function partitionedSearchAsStream (partition, ddoc, searchName, opts) {
return relax({
db: dbName,
path: '_partition/' + partition + '/_design/' + ddoc + '/_search/' + searchName,
path: '_partition/' + encodeURIComponent(partition) + '/_design/' + encodeURIComponent(ddoc) + '/_search/' + encodeURIComponent(searchName),
qs: opts,
stream: true
})
Expand All @@ -1110,15 +1110,15 @@ module.exports = exports = function dbScope (cfg) {
}
return relax({
db: dbName,
path: '_partition/' + partition + '/_design/' + ddoc + '/_view/' + viewName,
path: '_partition/' + encodeURIComponent(partition) + '/_design/' + encodeURIComponent(ddoc) + '/_view/' + encodeURIComponent(viewName),
qs: opts
}, callback)
}

function partitionedViewAsStream (partition, ddoc, viewName, opts) {
return relax({
db: dbName,
path: '_partition/' + partition + '/_design/' + ddoc + '/_view/' + viewName,
path: '_partition/' + encodeURIComponent(partition) + '/_design/' + encodeURIComponent(ddoc) + '/_view/' + encodeURIComponent(viewName),
qs: opts,
stream: true
})
Expand Down

0 comments on commit ac7b770

Please sign in to comment.