Skip to content

Commit

Permalink
isValidRev(): reject revs with more than one dash
Browse files Browse the repository at this point in the history
There are various places in the code where revs are assumed to include a single
dash character:

* pouchdb-adapter-idb/src/index.js:533: doc._rev = '0-' + (parseInt(oldRev.split('-')[1], 10) + 1);
* pouchdb-adapter-leveldb-core/src/index.js:1402: oldRev ? '0-' + (parseInt(oldRev.split('-')[1], 10) + 1) : '0-1';
* pouchdb-core/src/adapter.js:249: var parts = doc._rev.split('-');
* pouchdb-core/src/adapter.js:599: var splittedRev = doc._rev.split('-');
* pouchdb-core/src/adapter.js:623: const pathId = doc._rev.split('-')[1];
* pouchdb-merge/src/revExists.js:4: var splitRev = rev.split('-');

Follow-up to pouchdb#8931
  • Loading branch information
alxndrsn committed Apr 13, 2024
1 parent 16b6c07 commit 154cdb4
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/node_modules/pouchdb-core/src/adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ function attachmentNameError(name) {
}

function isValidRev(rev) {
return typeof rev === 'string' && /^\d+-/.test(rev);
return typeof rev === 'string' && /^\d+-[^-]*$/.test(rev);
}

class AbstractPouchDB extends EventEmitter {
Expand Down
1 change: 1 addition & 0 deletions tests/integration/test.basics.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ adapters.forEach(function (adapter) {
[
() => '-format',
() => 'bad-format',
() => '1-ok-bad',
() => ({}),
() => ({ toString:'2-abc' }),
() => ({ toString:'2-abc', indexOf:777 }),
Expand Down

0 comments on commit 154cdb4

Please sign in to comment.