From 154cdb4557919d5ac3835e7306fd94e82c352726 Mon Sep 17 00:00:00 2001 From: alxndrsn Date: Sat, 13 Apr 2024 08:49:05 +0000 Subject: [PATCH] isValidRev(): reject revs with more than one dash 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 https://github.com/pouchdb/pouchdb/pull/8931 --- packages/node_modules/pouchdb-core/src/adapter.js | 2 +- tests/integration/test.basics.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/node_modules/pouchdb-core/src/adapter.js b/packages/node_modules/pouchdb-core/src/adapter.js index d8b7fbe37a..9d8e35fd19 100644 --- a/packages/node_modules/pouchdb-core/src/adapter.js +++ b/packages/node_modules/pouchdb-core/src/adapter.js @@ -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 { diff --git a/tests/integration/test.basics.js b/tests/integration/test.basics.js index b86187c322..50a8072d1a 100644 --- a/tests/integration/test.basics.js +++ b/tests/integration/test.basics.js @@ -271,6 +271,7 @@ adapters.forEach(function (adapter) { [ () => '-format', () => 'bad-format', + () => '1-ok-bad', () => ({}), () => ({ toString:'2-abc' }), () => ({ toString:'2-abc', indexOf:777 }),