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

Inconsistent trailing slash behaviour #256

Open
Drowze opened this issue Mar 2, 2023 · 1 comment
Open

Inconsistent trailing slash behaviour #256

Drowze opened this issue Mar 2, 2023 · 1 comment

Comments

@Drowze
Copy link

Drowze commented Mar 2, 2023

Hello!

I've just found this another surprising behavior when writing a simple Hanami app, this time related to trailing slashes:

router = Hanami::Router.new do
  get "/users", to: ->_ { [200, {}, ['index users']] }
  get "/users/:id", to: ->_ {[200, {}, ['show user']]}
end

# without trailing slash it works as expected
router.call(Rack::MockRequest.env_for("/users"))
# => [200, {}, ["index users"]]

# with trailing slash, I get a 404
router.call(Rack::MockRequest.env_for("/users/"))
# => [404, {"Content-Length"=>"9"}, ["Not Found"]]

# interestingly, the show route works just fine
router.call(Rack::MockRequest.env_for("/users/1/"))
=> [200, {}, ["show user"]]

Version used: 2.0.2

@parndt
Copy link

parndt commented Sep 12, 2023

I've been putting this in my Gemfile:

gem "rack-rewrite"

And this in my config.ru

require "rack/rewrite"
use Rack::Rewrite do
  # remove trailing slashes
  r302 %r{(/.*)/(\?.*)?$}, "$1$2"
end

dNitza added a commit to dNitza/adamantium that referenced this issue Nov 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants