Skip to content

Commit

Permalink
Fix exception when a route is defined as a regex that does not includ…
Browse files Browse the repository at this point in the history
…e an optional trailing slash but accessed with a trailing slash. The trailing slash is now ignored consistent with the behavior of routes defined via strings or names.
  • Loading branch information
pdlug authored and ujifgc committed Apr 27, 2018
1 parent 1800c02 commit 6ed325b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion padrino-core/lib/padrino-core/path_router/matcher.rb
Expand Up @@ -21,7 +21,7 @@ def initialize(path, options = {})
def match(pattern)
if match_data = handler.match(pattern)
match_data
elsif mustermann? && pattern != "/" && pattern.end_with?("/")
elsif pattern != "/" && pattern.end_with?("/")
handler.match(pattern[0..-2])
end
end
Expand Down
10 changes: 10 additions & 0 deletions padrino-core/test/test_routing.rb
Expand Up @@ -156,6 +156,16 @@ def match(string)
assert_equal "My lucky number: 99 99", body
end

it 'should ignore trailing slashes' do
mock_app do
get(%r./trailing.) { "slash" }
end
get "/trailing"
assert_equal "slash", body
get "/trailing/"
assert_equal "slash", body
end

it 'should accept regexp routes with generate with :generate_with' do
mock_app do
get(%r{/fob|/baz}, :name => :foo, :generate_with => '/fob') { "regexp" }
Expand Down

0 comments on commit 6ed325b

Please sign in to comment.