From ae4332ff47e8d7bf8059b618a3f71b2620d4d7be Mon Sep 17 00:00:00 2001 From: achingbrain Date: Mon, 25 Nov 2019 11:39:25 +0100 Subject: [PATCH 1/2] fix: allow empty prefix option --- index.js | 2 +- test/custom-test.js | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index ce0d229..098437c 100644 --- a/index.js +++ b/index.js @@ -33,7 +33,7 @@ function Level (location, opts) { } this.location = location - this.prefix = opts.prefix || DEFAULT_PREFIX + this.prefix = opts.prefix === undefined ? DEFAULT_PREFIX : opts.prefix this.version = parseInt(opts.version || 1, 10) } diff --git a/test/custom-test.js b/test/custom-test.js index 86aafc9..b9c4827 100644 --- a/test/custom-test.js +++ b/test/custom-test.js @@ -47,6 +47,27 @@ module.exports = function (leveljs, test, testCommon) { }) }) + test('empty prefix', function (t) { + var db = testCommon.factory({ prefix: '' }) + + t.ok(db.location, 'instance has location property') + t.is(db.prefix, '', 'instance has prefix property') + + db.open(function (err) { + t.notOk(err, 'no open error') + + var idb = db.db + var databaseName = idb.name + var storeNames = idb.objectStoreNames + + t.is(databaseName, db.location, 'database name is prefixed') + t.is(storeNames.length, 1, 'created 1 object store') + t.is(storeNames.item(0), db.location, 'object store name equals location') + + db.close(t.end.bind(t)) + }) + }) + test('put Buffer value, get Buffer value', function (t) { var level = testCommon.factory() level.open(function (err) { From afa36cca9b1c63fb57cc2e19cf29629213f533df Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Mon, 25 Nov 2019 10:57:14 +0000 Subject: [PATCH 2/2] fix: only set prefix to default if prefix is not null or undefined Co-Authored-By: Vincent Weevers --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 098437c..702da84 100644 --- a/index.js +++ b/index.js @@ -33,7 +33,7 @@ function Level (location, opts) { } this.location = location - this.prefix = opts.prefix === undefined ? DEFAULT_PREFIX : opts.prefix + this.prefix = opts.prefix == null ? DEFAULT_PREFIX : opts.prefix this.version = parseInt(opts.version || 1, 10) }