Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix iterating buffer keys that contain bytes 196-255 #88

Merged
merged 2 commits into from
Apr 3, 2020

Conversation

vweevers
Copy link
Member

@vweevers vweevers commented Feb 28, 2020

Closes #87. Previously (in any version) keys containing bytes 196-255 were wrongly excluded by the range logic of subleveldown. The fix is not breaking for most folks.

It's breaking if you:

  • Use the default separator and prefixes that contain " (byte 34)
  • Use a custom separator that doesn't sort 2 positions before characters used in your prefixes. For example with separator / (byte 47) prefixes must use characters greater than 0 (byte 48).

In either case, an error will be thrown from the constructor.

@vweevers vweevers added the semver-patch Bug fixes that are backward compatible label Feb 28, 2020
@vweevers vweevers removed the semver-patch Bug fixes that are backward compatible label Feb 28, 2020
if (Buffer.isBuffer(x) && !x.length) x = END
return concat(self.prefix, x || '\xff')
if (!x || isEmptyBuffer(x)) {
return self.prefix.slice(0, -1) + ceiling
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An example: if the separator is ! then the "ceiling" is ". If you have a bunch of sublevels with prefixes ['!a!', '!a!!a!', '!aa!', '!b!'] and you want to get everything in !a!, then that's everything less than !a".

$ node
> ['!a!', '!a!!a!', '!aa!', '!b!', '!a"'].sort()
[ '!a!', '!a!!a!', '!a"', '!aa!', '!b!' ]

Is there a case where this doesn't work? Apart from a custom separator that leaves no room for the ceiling, like sub(db, '0', { separator: '/' }).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a really good idea also for defining keys in general cases and get a range of it.

Previously (in any version) such keys were wrongly excluded by the
range logic of subleveldown. The fix is not breaking for most folks.

It's breaking if you:

- Use the default separator and prefixes that contain '"' (byte 34)
- Use a custom separator that doesn't sort 2 positions before
  characters used in your prefixes. For example with separator '/'
  (byte 47) prefixes must use characters greater than '0' (byte 48).

In either case, an error will be thrown from the constructor.
@vweevers vweevers added the semver-major Changes that break backward compatibility label Feb 29, 2020
@vweevers vweevers changed the title Fix iterating buffer keys with bytes above 196 Fix iterating buffer keys that contain bytes 196-255 Feb 29, 2020
@vweevers vweevers removed the request for review from ralphtheninja February 29, 2020 13:28
README.md Outdated Show resolved Hide resolved
leveldown.js Show resolved Hide resolved
@vweevers vweevers merged commit 01b2d50 into master Apr 3, 2020
@vweevers vweevers deleted the fix-buffer-keys branch April 3, 2020 19:19
@vweevers
Copy link
Member Author

vweevers commented Apr 5, 2020

5.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver-major Changes that break backward compatibility
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Possible issue with buffer keys
2 participants