mirror of
https://gitea.invidious.io/iv-org/shard-radix.git
synced 2024-08-15 00:43:21 +00:00
Merge pull request #3 from luislavena/detect-multiple-params
Correctly build key from detected parameters
This commit is contained in:
commit
88863daab2
2 changed files with 31 additions and 1 deletions
|
@ -340,6 +340,34 @@ module Radix
|
|||
end
|
||||
end
|
||||
|
||||
context "dealing with multiple named parameters" do
|
||||
it "finds matching path" do
|
||||
tree = Tree.new
|
||||
tree.add "/", :root
|
||||
tree.add "/:section/:page", :static_page
|
||||
|
||||
result = tree.find("/about/shipping")
|
||||
result.found?.should be_true
|
||||
result.key.should eq("/:section/:page")
|
||||
result.payload.should eq(:static_page)
|
||||
end
|
||||
|
||||
it "returns named parameters in result" do
|
||||
tree = Tree.new
|
||||
tree.add "/", :root
|
||||
tree.add "/:section/:page", :static_page
|
||||
|
||||
result = tree.find("/about/shipping")
|
||||
result.found?.should be_true
|
||||
|
||||
result.params.has_key?("section").should be_true
|
||||
result.params["section"].should eq("about")
|
||||
|
||||
result.params.has_key?("page").should be_true
|
||||
result.params["page"].should eq("shipping")
|
||||
end
|
||||
end
|
||||
|
||||
context "dealing with both catch all and named parameters" do
|
||||
it "finds matching path" do
|
||||
tree = Tree.new
|
||||
|
|
|
@ -257,7 +257,9 @@ module Radix
|
|||
path_size = _detect_param_size(path_reader)
|
||||
|
||||
# obtain key and value using calculated sizes
|
||||
name = key_reader.string.byte_slice(key_reader.pos + 1, key_size)
|
||||
# for name: skip ':' by moving one character forward and compensate
|
||||
# key size.
|
||||
name = key_reader.string.byte_slice(key_reader.pos + 1, key_size - 1)
|
||||
value = path_reader.string.byte_slice(path_reader.pos, path_size)
|
||||
|
||||
# add this information to result
|
||||
|
|
Loading…
Reference in a new issue