Anchors should be allowed on constraints that are not on path segments
This commit is contained in:
parent
1deeaf5495
commit
401c1835af
@ -66,6 +66,18 @@ def normalize_options!
|
||||
end
|
||||
|
||||
@options.merge!(default_controller_and_action(to_shorthand))
|
||||
|
||||
requirements.each do |name, requirement|
|
||||
# segment_keys.include?(k.to_s) || k == :controller
|
||||
next unless Regexp === requirement && !constraints[name]
|
||||
|
||||
if requirement.source =~ %r{\A(\\A|\^)|(\\Z|\\z|\$)\Z}
|
||||
raise ArgumentError, "Regexp anchor characters are not allowed in routing requirements: #{requirement.inspect}"
|
||||
end
|
||||
if requirement.multiline?
|
||||
raise ArgumentError, "Regexp multiline option not allowed in routing requirements: #{requirement.inspect}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# match "account/overview"
|
||||
@ -113,15 +125,6 @@ def requirements
|
||||
@requirements ||= (@options[:constraints].is_a?(Hash) ? @options[:constraints] : {}).tap do |requirements|
|
||||
requirements.reverse_merge!(@scope[:constraints]) if @scope[:constraints]
|
||||
@options.each { |k, v| requirements[k] = v if v.is_a?(Regexp) }
|
||||
|
||||
requirements.values.grep(Regexp).each do |requirement|
|
||||
if requirement.source =~ %r{\A(\\A|\^)|(\\Z|\\z|\$)\Z}
|
||||
raise ArgumentError, "Regexp anchor characters are not allowed in routing requirements: #{requirement.inspect}"
|
||||
end
|
||||
if requirement.multiline?
|
||||
raise ArgumentError, "Regexp multiline option not allowed in routing requirements: #{requirement.inspect}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -834,6 +834,14 @@ def test_route_with_parameter_shell
|
||||
assert_equal({:controller => 'pages', :action => 'show', :id => '10'}, set.recognize_path('/page/10'))
|
||||
end
|
||||
|
||||
def test_route_constraints_on_request_object_with_anchors_are_valid
|
||||
assert_nothing_raised do
|
||||
set.draw do
|
||||
match 'page/:id' => 'pages#show', :constraints => { :host => /^foo$/ }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_route_constraints_with_anchor_chars_are_invalid
|
||||
assert_raise ArgumentError do
|
||||
set.draw do
|
||||
|
Loading…
Reference in New Issue
Block a user