Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes head creation on route globbing #68

Merged
merged 2 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions spec/integration_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/lucky_router/fragment.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down