This repository has been archived by the owner on Dec 1, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 52
Range tests on zero-length buffer+string are incompatible with bytewise, charwise & IDB #318
Labels
bug
Something isn't working
Comments
Note that |
Correction: unlike Click to expandfunction cmp (a, b) {
// # https://www.w3.org/TR/IndexedDB-2/#key-construct
// "Let ta be the type of a, let tb be the type of b."
var ta = type(a)
var tb = type(b)
// "If ta is array and tb is binary, string, date or number, return 1."
if (ta === 'array' && (tb === 'binary' || tb === 'string' || tb === 'date' || tb === 'number')) return 1
// "If tb is array and ta is binary, string, date or number, return -1."
if (tb === 'array' && (ta === 'binary' || ta === 'string' || ta === 'date' || ta === 'number')) return -1
// "If ta is binary and tb is string, date or number, return 1."
if (ta === 'binary' && (tb === 'string' || tb === 'date' || tb === 'number')) return 1
// "If tb is binary and ta is string, date or number, return -1."
if (tb === 'binary' && (ta === 'string' || ta === 'date' || ta === 'number')) return -1
// "If ta is string and tb is date or number, return 1."
if (ta === 'string' && (tb === 'date' || tb === 'number')) return 1
// "If tb is string and ta is date or number, return -1."
if (tb === 'string' && (ta === 'date' || ta === 'number')) return -1
// "If ta is date and tb is number, return 1."
if (ta === 'date' && (tb === 'number')) return 1
// "If tb is date and ta is number, return -1."
if (tb === 'date' && (ta === 'number')) return -1
throw new Error('value comparison is not implemented')
}
function type (value) {
const t = typeof value
if (t === 'string' || t === 'number') return t
if (Buffer.isBuffer(value)) return 'binary' // stored same as arraybuffer
if (Array.isArray(value)) return 'array'
if (Object.prototype.toString.call(value) === '[object Date]') return 'date'
throw new Error('unsupported type')
}
// [ 3, <date>, '', <Buffer>, [] ]
console.log([
new Date(),
'',
3,
[],
Buffer.alloc(0)
].sort(cmp)) |
vweevers
added a commit
to Level/level-js
that referenced
this issue
Dec 25, 2018
This was referenced Dec 25, 2018
vweevers
added a commit
to Level/level-js
that referenced
this issue
Dec 27, 2018
This reverts commit 2d62675.
vweevers
added a commit
to Level/level-js
that referenced
this issue
Dec 27, 2018
This reverts commit 2d62675.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
They assume that a zero-length string or zero-length Buffer means "not defined". IMO that should be left up to an implementation.
abstract-leveldown/test/iterator-range-test.js
Lines 313 to 345 in fd64104
In
bytewise
,charwise
and IndexedDB, an empty string is a significant type. In all three, the sort order of types is:null
(not supported by IDB)false
(not supported by IDB)true
(not supported by IDB)number
(numeric)date
(numeric, epoch offset)binary
(bitwise) (not supported bycharwise
and IDB First Edition)string
(lexicographic)array
(componentwise)undefined
(not supported by IDB)For example,
charwise
encodes an empty string as'J'
.I suggest:
abstract-leveldown
, document behavior (Remove range tests that assumed zero-length strings or Buffers meant "not defined" #319) (semver-patch)leveldown
, document the behavior (Add tests for zero-length range options leveldown#573) (semver-patch or RC, depending on when this lands)level-js
on sort order of the above types, document the behavior (Fix zero-length range options level-js#156) (release as part of upgrade toabstract-leveldown@6
)The text was updated successfully, but these errors were encountered: