Skip to content
This repository was archived by the owner on Dec 2, 2024. It is now read-only.

Commit 2f97b6e

Browse files
committed
breaking: don't serialize true/false/NaN keys, have IDB reject them
1 parent c94d85a commit 2f97b6e

5 files changed

+3
-46
lines changed

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ Note that this behavior is slightly different from values due to the way that In
122122
If the environment does not support a type, it will throw an error which `level-js` catches and passes to the callbacks of `get`, `put`, `del`, `batch` or an iterator. Exceptions are:
123123

124124
- `null` and `undefined`: rejected early by `abstract-leveldown`
125-
- Boolean and `NaN`: though invalid per the IndexedDB specification, they are converted to strings for `abstract-leveldown` compatibility;
126125
- Binary and array keys: if not supported by the environment, `level-js` falls back to `String(key)`.
127126

128127
### Normalization

index.js

-4
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,6 @@ Level.prototype._serializeKey = function (key) {
145145
return Level.binaryKeys ? key : key.toString()
146146
} else if (Array.isArray(key)) {
147147
return Level.arrayKeys ? key.map(this._serializeKey, this) : String(key)
148-
} else if (typeof key === 'boolean' || (typeof key === 'number' && isNaN(key))) {
149-
// These types are invalid per the IndexedDB spec and ideally we'd treat
150-
// them that way, but they're valid per the current abstract test suite.
151-
return String(key)
152148
} else {
153149
return key
154150
}

test/index.js

-1
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,3 @@ require('./custom-test')(leveljs, test, testCommon)
3434
require('./structured-clone-test')(leveljs, test, testCommon)
3535
require('./key-type-test')(leveljs, test, testCommon)
3636
require('./key-type-illegal-test')(leveljs, test, testCommon)
37-
require('./key-type-stringified-test')(leveljs, test, testCommon)

test/key-type-illegal-test.js

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ var illegalTypes = [
1313
{ name: 'DOMNode', key: global.document, error: 'DataError' },
1414
{ name: 'Boolean(true)', key: new Boolean(true), error: 'DataError' }, // eslint-disable-line
1515
{ name: 'Boolean(false)', key: new Boolean(false), error: 'DataError' }, // eslint-disable-line
16+
{ name: 'true', key: true, error: 'DataError' },
17+
{ name: 'false', key: false, error: 'DataError' },
18+
{ name: 'NaN', key: NaN, error: 'DataError' }
1619
]
1720

1821
// These are only tested if the environment supports array keys.

test/key-type-stringified-test.js

-40
This file was deleted.

0 commit comments

Comments
 (0)