aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionpack/lib/action_controller/routing.rb2
-rw-r--r--actionpack/test/controller/routing_test.rb23
2 files changed, 24 insertions, 1 deletions
diff --git a/actionpack/lib/action_controller/routing.rb b/actionpack/lib/action_controller/routing.rb
index b7eb603463..9628c1f0ad 100644
--- a/actionpack/lib/action_controller/routing.rb
+++ b/actionpack/lib/action_controller/routing.rb
@@ -489,7 +489,7 @@ module ActionController
Regexp.new "\\A#{regexp.source}\\Z" if regexp
end
def regexp_chunk
- regexp ? regexp.source : "([^#{Routing::SEPARATORS.join}]+)"
+ regexp ? "(#{regexp.source})" : "([^#{Routing::SEPARATORS.join}]+)"
end
def build_pattern(pattern)
diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb
index 3f8397c95e..6388c6af03 100644
--- a/actionpack/test/controller/routing_test.rb
+++ b/actionpack/test/controller/routing_test.rb
@@ -1230,6 +1230,29 @@ class RouteSetTest < Test::Unit::TestCase
ensure
Object.send(:remove_const, :PeopleController)
end
+
+ def test_typo_recognition
+ Object.const_set(:ArticlesController, Class.new)
+
+ set.draw do |map|
+ map.connect 'articles/:year/:month/:day/:title',
+ :controller => 'articles', :action => 'permalink',
+ :year => /\d{4}/, :day => /\d{1,2}/, :month => /\d{1,2}/
+ end
+
+ request.path = "/articles/2005/11/05/a-very-interesting-article"
+ request.method = :get
+ assert_nothing_raised { set.recognize(request) }
+ assert_equal("permalink", request.path_parameters[:action])
+ assert_equal("2005", request.path_parameters[:year])
+ assert_equal("11", request.path_parameters[:month])
+ assert_equal("05", request.path_parameters[:day])
+ assert_equal("a-very-interesting-article", request.path_parameters[:title])
+
+ ensure
+ Object.send(:remove_const, :ArticlesController)
+ end
+
def test_recognize_with_conditions_and_format
Object.const_set(:PeopleController, Class.new)