Unexpected suffix match
RX14 opened this issue · 7 comments
Not sure what's going on here at all...
require "radix"
t = Radix::Tree(Symbol).new
t.add("/prefix/", :root)
t.add("/prefix/foo", :foo)
t.find("/foo")
returns a match...
Hello @RX14, thanks for your patience.
I just ran your code and doesn't find a result:
require "radix"
tree = Radix::Tree(Symbol).new
tree.add("/prefix", :one)
tree.add("/prefix/foo", :two)
result = tree.find("/foo")
pp result.found? # => false
Please note that #find
returns a result object, not a boolean response. (see docs)
If that is not the case, can you provide another example of the issue?
Cheers.
Using Radix 0.3.9
, crystal 0.33.0
require "radix"
t = Radix::Tree(Symbol).new
t.add("/prefix/", :root)
t.add("/prefix/foo", :foo)
res = t.find("/foo")
p res, res.found?
$ crystal radix.cr
#<Radix::Result(Symbol):0x7f8cdb121740 @key=nil, @payload=:foo, @nodes=[#<Radix::Node(Symbol):0x7f8cdb128f00 @payload=:root, @priority=8, @children=[#<Radix::Node(Symbol):0x7f8cdb128eb0 @payload=:foo, @priority=3, @children=[], @kind=Normal, @key="foo", @placeholder=false>], @kind=Normal, @key="/prefix/", @placeholder=false>, #<Radix::Node(Symbol):0x7f8cdb128eb0 @payload=:foo, @priority=3, @children=[], @kind=Normal, @key="foo", @placeholder=false>], @params={}>
true
Ah, i see:
the difference between your code and mine is that your code has /prefix
and mine has /prefix/
. I've checked and the trailing slash breaks this.
Thanks @RX14, definitely didn't see the slash at the end 🤦♂
I remember had a branch that sanitizes entries by removing trialing and repeated slashes.
Will try to take a look soon and get back to you.
Cheers.
So I should strip all training slashes as a workaround for now?
@RX14 yeah, that will be a good workaround for the time being, thank you for your patience.