mirror of
https://gitea.invidious.io/iv-org/shard-radix.git
synced 2024-08-15 00:43:21 +00:00
Merge pull request #22 from luislavena/fix-incorrect-shared-key
Fix incorrect lookup on non-shared partial keys
This commit is contained in:
commit
7460033db3
3 changed files with 19 additions and 0 deletions
|
@ -5,6 +5,8 @@ This project aims to comply with [Semantic Versioning](http://semver.org/),
|
|||
so please check *Changed* and *Removed* notes before upgrading.
|
||||
|
||||
## [Unreleased]
|
||||
### Fixed
|
||||
- Correct lookup issue caused by incorrect comparison of shared key [#21](https://github.com/luislavena/radix/issues/21)
|
||||
|
||||
## [0.3.7] - 2017-02-04
|
||||
### Fixed
|
||||
|
|
|
@ -323,6 +323,17 @@ module Radix
|
|||
result.payload.should eq(:abc)
|
||||
end
|
||||
|
||||
it "finds matching path across separator" do
|
||||
tree = Tree(Symbol).new
|
||||
tree.add "/products", :products
|
||||
tree.add "/product/new", :product_new
|
||||
|
||||
result = tree.find("/products")
|
||||
result.found?.should be_true
|
||||
result.key.should eq("/products")
|
||||
result.payload.should eq(:products)
|
||||
end
|
||||
|
||||
it "finds matching path across parents" do
|
||||
tree = Tree(Symbol).new
|
||||
tree.add "/", :root
|
||||
|
|
|
@ -432,11 +432,17 @@ module Radix
|
|||
# _shared_key?("foo", "bar") # => false (mismatch at 1st character)
|
||||
# _shared_key?("foo/bar", "foo/baz") # => true (only `foo` is compared)
|
||||
# _shared_key?("zipcode", "zip") # => true (only `zip` is compared)
|
||||
# _shared_key?("s", "/new") # => false (1st character is a separator)
|
||||
# ```
|
||||
private def _shared_key?(path, key)
|
||||
path_reader = Char::Reader.new(path)
|
||||
key_reader = Char::Reader.new(key)
|
||||
|
||||
if (path_reader.current_char != key_reader.current_char) &&
|
||||
_check_markers(key_reader.current_char)
|
||||
return false
|
||||
end
|
||||
|
||||
different = false
|
||||
|
||||
while (path_reader.has_next? && !_check_markers(path_reader.current_char)) &&
|
||||
|
|
Loading…
Reference in a new issue