Skip to content

Commit 4f39bd2

Browse files
authored
(#8602) - fix tests for local doc IDs
This changes tests for local doc IDs inline with documented behaviour to test that the id starts with "_local/" instead of just "_local".
1 parent 1b12b0d commit 4f39bd2

4 files changed

Lines changed: 5 additions & 5 deletions

File tree

‎packages/node_modules/pouchdb-adapter-http/src/index.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function encodeDocId(id) {
5353
if (/^_design/.test(id)) {
5454
return '_design/' + encodeURIComponent(id.slice(8));
5555
}
56-
if (/^_local/.test(id)) {
56+
if (id.startsWith('_local/')) {
5757
return '_local/' + encodeURIComponent(id.slice(7));
5858
}
5959
return encodeURIComponent(id);

‎packages/node_modules/pouchdb-adapter-indexeddb/src/allDocs.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ export default function (txn, metadata, opts, callback) {
204204
if (!doc) { return; }
205205

206206
// Skip local docs
207-
if (/^_local/.test(doc.id)) {
207+
if (doc.id.startsWith('_local/')) {
208208
return e.target.result.continue();
209209
}
210210

‎packages/node_modules/pouchdb-adapter-indexeddb/src/bulkDocs.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export default function (api, req, opts, metadata, dbOpts, idbChanges, callback)
3737

3838
// We only need to track 1 revision for local documents
3939
function docsRevsLimit(doc) {
40-
return /^_local/.test(doc.id) ? 1 : revsLimit;
40+
return doc.id.startsWith('_local/') ? 1 : revsLimit;
4141
}
4242

4343
function rootIsMissing(doc) {
@@ -195,7 +195,7 @@ export default function (api, req, opts, metadata, dbOpts, idbChanges, callback)
195195
var winningRev = calculateWinningRev(doc);
196196
// rev of new doc for attachments and to return it
197197
var writtenRev = doc.rev;
198-
var isLocal = /^_local/.test(doc.id);
198+
var isLocal = doc.id.startsWith('_local/');
199199

200200
var theDoc = doc.revs[winningRev].data;
201201

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
function isLocalId(id) {
2-
return (/^_local/).test(id);
2+
return typeof id === 'string' && id.startsWith('_local/');
33
}
44

55
export default isLocalId;

0 commit comments

Comments
 (0)