From 6ed325b8fcca439a225d5fd42a509f7a8b48d391 Mon Sep 17 00:00:00 2001 From: Paul Dlug Date: Wed, 21 Feb 2018 16:56:44 -0500 Subject: [PATCH] Fix exception when a route is defined as a regex that does not include 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. --- padrino-core/lib/padrino-core/path_router/matcher.rb | 2 +- padrino-core/test/test_routing.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/padrino-core/lib/padrino-core/path_router/matcher.rb b/padrino-core/lib/padrino-core/path_router/matcher.rb index 0f5b947e0..fd9816f05 100644 --- a/padrino-core/lib/padrino-core/path_router/matcher.rb +++ b/padrino-core/lib/padrino-core/path_router/matcher.rb @@ -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 diff --git a/padrino-core/test/test_routing.rb b/padrino-core/test/test_routing.rb index 5aab6e293..bc84aaf97 100644 --- a/padrino-core/test/test_routing.rb +++ b/padrino-core/test/test_routing.rb @@ -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" }