fix(Tree): corrects lookup issue with catch all and shared key

Lookup was failing when part of the given path matched a key at the
first character, even when the rest of the key didn't match.

It was not possible place a catch all an another key at the same
level that started with same character.

This change ensures that all shared part between path and key is
compared prior assuming usage of that node as part of the lookup.

Closes #14
This commit is contained in:
Luis Lavena 2016-11-24 20:52:07 -03:00
parent 6880b341a6
commit 95b6638f1a
3 changed files with 62 additions and 3 deletions

View file

@ -404,6 +404,18 @@ module Radix
result.found?.should be_true
result.key.should eq("/members")
end
it "does prefer catch all over specific key with partially shared key" do
tree = Tree(Symbol).new
tree.add "/orders/*anything", :orders_catch_all
tree.add "/orders/closed", :closed_orders
result = tree.find("/orders/cancelled")
result.found?.should be_true
result.key.should eq("/orders/*anything")
result.params.has_key?("anything").should be_true
result.params["anything"].should eq("cancelled")
end
end
context "dealing with named parameters" do