diff --git a/spec/integration_spec.cr b/spec/integration_spec.cr index 74bffcd..628feff 100644 --- a/spec/integration_spec.cr +++ b/spec/integration_spec.cr @@ -194,6 +194,19 @@ describe LuckyRouter do }) end + it "matches both get and head with route globbing" do + router = LuckyRouter::Matcher(Symbol).new + router.add("get", "/posts/something/*", :post_index) + + router.match!("get", "/posts/something/1").params.should eq({ + "glob" => "1", + }) + + router.match!("head", "/posts/something/1").params.should eq({ + "glob" => "1", + }) + end + it "matches a route with more than 16 segments" do router = LuckyRouter::Matcher(Symbol).new router.add("get", "/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/:z", :match) diff --git a/src/lucky_router/fragment.cr b/src/lucky_router/fragment.cr index 838f065..8db368e 100644 --- a/src/lucky_router/fragment.cr +++ b/src/lucky_router/fragment.cr @@ -91,7 +91,7 @@ class LuckyRouter::Fragment(T) def add_part(path_part : PathPart) : Fragment(T) if path_part.glob? - self.glob_part = Fragment(T).new(path_part: path_part) + self.glob_part ||= Fragment(T).new(path_part: path_part) elsif path_part.path_variable? existing = self.dynamic_parts.find { |fragment| fragment.path_part == path_part } return existing if existing