aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorNicholas Seckar <nseckar@gmail.com>2006-08-15 02:04:11 +0000
committerNicholas Seckar <nseckar@gmail.com>2006-08-15 02:04:11 +0000
commit7678d123a7e46edcf418a6959b615e2387b7fad6 (patch)
tree864240d0f3056efe1aec7b2a752dbe0c1853c05a /actionpack
parent5baf7462c7a6dc6b30eec2b03735fee15e5b0dca (diff)
downloadrails-7678d123a7e46edcf418a6959b615e2387b7fad6.tar.gz
rails-7678d123a7e46edcf418a6959b615e2387b7fad6.tar.bz2
rails-7678d123a7e46edcf418a6959b615e2387b7fad6.zip
Relax Routing's anchor pattern warning; it was preventing use of [^/] inside restrictions.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4763 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/CHANGELOG2
-rw-r--r--actionpack/lib/action_controller/routing.rb2
-rw-r--r--actionpack/test/controller/routing_test.rb38
3 files changed, 41 insertions, 1 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index ff636b7984..175d3f46bf 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Relax Routing's anchor pattern warning; it was preventing use of [^/] inside restrictions. [Nicholas Seckar]
+
* Add controller_paths variable to Routing. [Nicholas Seckar]
* Fix assert_redirected_to issue with named routes for module controllers. [Rick Olson]
diff --git a/actionpack/lib/action_controller/routing.rb b/actionpack/lib/action_controller/routing.rb
index 8c85c712a0..7b9bbc3b5a 100644
--- a/actionpack/lib/action_controller/routing.rb
+++ b/actionpack/lib/action_controller/routing.rb
@@ -681,7 +681,7 @@ module ActionController
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|\^|\$}
+ if requirement.source =~ %r{\A(\\A|\^)|(\\Z|\\z|\$)\Z}
raise ArgumentError, "Regexp anchor characters are not allowed in routing requirements: #{requirement.inspect}"
end
segment.regexp = requirement
diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb
index 4c3a910bcd..fc8bc82357 100644
--- a/actionpack/test/controller/routing_test.rb
+++ b/actionpack/test/controller/routing_test.rb
@@ -109,6 +109,30 @@ class LegacyRouteSetTests < Test::Unit::TestCase
assert_equal '/admin/user/foo', rs.generate(:controller => "admin/user", :admintoken => "foo", :action => "index")
assert_equal '/content/foo', rs.generate(:controller => "content", :action => "foo")
end
+
+ def test_route_with_regexp_and_dot
+ rs.draw do |map|
+ map.connect ':controller/:action/:file',
+ :controller => /admin|user/,
+ :action => /upload|download/,
+ :defaults => {:file => nil},
+ :requirements => {:file => %r{[^/]+(\.[^/]+)?}}
+ end
+ # Without a file extension
+ assert_equal '/user/download/file',
+ rs.generate(:controller => "user", :action => "download", :file => "file")
+ assert_equal(
+ {:controller => "user", :action => "download", :file => "file"},
+ rs.recognize_path("/user/download/file"))
+
+ # Now, let's try a file with an extension, really a dot (.)
+ assert_equal '/user/download/file.jpg',
+ rs.generate(
+ :controller => "user", :action => "download", :file => "file.jpg")
+ assert_equal(
+ {:controller => "user", :action => "download", :file => "file.jpg"},
+ rs.recognize_path("/user/download/file.jpg"))
+ end
def test_basic_named_route
rs.add_named_route :home, '', :controller => 'content', :action => 'list'
@@ -1009,6 +1033,20 @@ class RouteBuilderTest < Test::Unit::TestCase
assert_equal %r/\w+/, segments[7].regexp
assert segments[7].optional?
end
+
+ def test_assign_route_options_with_anchor_chars
+ segments = builder.segments_for_route_path '/cars/:action/:person/:car/'
+ defaults = {:action => 'buy', :person => nil, :car => nil}
+ requirements = {:person => /\w+/, :car => /^\w+$/}
+
+ assert_raises ArgumentError do
+ route_requirements = builder.assign_route_options(segments, defaults, requirements)
+ end
+
+ requirements[:car] = /[^\/]+/
+ route_requirements = builder.assign_route_options(segments, defaults, requirements)
+ end
+
def test_optional_segments_preceding_required_segments
segments = builder.segments_for_route_path '/cars/:action/:person/:car/'