提交 127ee8c8 编写于 作者: N Nicholas Seckar

Make Routing noisy when an anchor regexp is assigned to a segment. Closes #5674

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4677 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 900afae4
*SVN*
* Make Routing noisy when an anchor regexp is assigned to a segment. #5674 [francois.beausoleil@gmail.com]
* Added months and years to the resolution of DateHelper#distance_of_time_in_words, such that "60 days ago" becomes "2 months ago" #5611 [pjhyett@gmail.com]
>>>>>>> .r4676
* Short documentation to mention use of Mime::Type.register. #5710 [choonkeat@gmail.com]
* Make controller_path available as an instance method. #5724 [jmckible@gmail.com]
......
......@@ -694,6 +694,9 @@ def assign_route_options(segments, defaults, requirements)
segment = segment_named[key]
if segment
raise TypeError, "#{key}: requirements on a path segment must be regular expressions" unless requirement.is_a?(Regexp)
if requirement.source =~ %r{\\A|\\Z|\\z|\^|\$}
raise ArgumentError, "Regexp anchor characters are not allowed in routing requirements: #{requirement.inspect}"
end
segment.regexp = requirement
else
route_requirements[key] = requirement
......
......@@ -150,7 +150,7 @@ def test_named_route_without_hash
def test_named_route_with_regexps
rs.draw do |map|
map.article 'page/:year/:month/:day/:title', :controller => 'page', :action => 'show',
:year => /^\d+$/, :month => /^\d+$/, :day => /^\d+$/
:year => /\d+/, :month => /\d+/, :day => /\d+/
map.connect ':controller/:action/:id'
end
x = setup_for_named_route.new
......@@ -1252,6 +1252,55 @@ def test_route_with_parameter_shell
end
end
def test_route_requirements_with_anchor_chars_are_invalid
assert_raises ArgumentError do
set.draw do |map|
map.connect 'page/:id', :controller => 'pages', :action => 'show', :id => /^\d+/
end
end
assert_raises ArgumentError do
set.draw do |map|
map.connect 'page/:id', :controller => 'pages', :action => 'show', :id => /\A\d+/
end
end
assert_raises ArgumentError do
set.draw do |map|
map.connect 'page/:id', :controller => 'pages', :action => 'show', :id => /\d+$/
end
end
assert_raises ArgumentError do
set.draw do |map|
map.connect 'page/:id', :controller => 'pages', :action => 'show', :id => /\d+\Z/
end
end
assert_raises ArgumentError do
set.draw do |map|
map.connect 'page/:id', :controller => 'pages', :action => 'show', :id => /\d+\z/
end
end
assert_nothing_raised do
set.draw do |map|
map.connect 'page/:id', :controller => 'pages', :action => 'show', :id => /\d+/, :name => /^(david|jamis)/
end
assert_raises ActionController::RoutingError do
set.generate :controller => 'pages', :action => 'show', :id => 10
end
end
end
def test_non_path_route_requirements_match_all
set.draw do |map|
map.connect 'page/37s', :controller => 'pages', :action => 'show', :name => /(jamis|david)/
end
assert_equal '/page/37s', set.generate(:controller => 'pages', :action => 'show', :name => 'jamis')
assert_raises ActionController::RoutingError do
set.generate(:controller => 'pages', :action => 'show', :name => 'not_jamis')
end
assert_raises ActionController::RoutingError do
set.generate(:controller => 'pages', :action => 'show', :name => 'nor_jamis_and_david')
end
end
def test_recognize_with_encoded_id_and_regex
set.draw do |map|
map.connect 'page/:id', :controller => 'pages', :action => 'show', :id => /[a-zA-Z0-9 ]+/
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册