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

Fix stack overflows with page(func, func) #117

Merged
merged 2 commits into from
Dec 6, 2020
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
5 changes: 4 additions & 1 deletion src/routing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,17 @@ function matchpath!(target, req)
return true
end

route(p, app...) = branch(req -> matchpath!(p, req), app...)
route(p::Vector, app...) = branch(req -> matchpath!(p, req), app...)
route(p::AbstractString, app...) = route(splitpath(p), app...)
route(app...) = route([], app...)
route(app::Function, p) = route(p, app)
route(app1::Function, app2::Function) = route([], app1, app2)

page(p::Vector, app...) = branch(req -> length(p) == length(req[:path]) && matchpath!(p, req), app...)
page(p::AbstractString, app...) = page(splitpath(p), app...)
page(app...) = page([], app...)
page(app::Function, p) = page(p, app)
page(app1::Function, app2::Function) = page([], app1, app2)

# Query routing

Expand Down
11 changes: 11 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,14 @@ serve(test, 8001)
@test String(HTTP.get("http://localhost:8001/badurl";
status_exception=false).body) ==
"Internal server error"

# Test page and route are callable without a string argument
# (previously the first two raised StackOverflowError)
@test page(identity, identity) isa Function
@test route(identity, identity) isa Function
@test page(identity) isa Function
@test route(identity) isa Function

# Test you can pass the string last if you really want.
@test page(identity, "") isa Function
@test route(identity, "") isa Function