aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-01-12 16:23:18 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-01-12 16:23:18 +0000
commitd3a8d5f93c6eee44a23f26fcb6573e77625f41b0 (patch)
treec9d2e999d956c8d85dbbd0997008b84137857d4d /actionpack
parentcb8a020ec941101902307b81f4a1a6b9ac6d224d (diff)
downloadrails-d3a8d5f93c6eee44a23f26fcb6573e77625f41b0.tar.gz
rails-d3a8d5f93c6eee44a23f26fcb6573e77625f41b0.tar.bz2
rails-d3a8d5f93c6eee44a23f26fcb6573e77625f41b0.zip
Fixed url rewriter confusion when the controller or action name was a substring of the controller_prefix or action_prefix
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@398 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/CHANGELOG2
-rw-r--r--actionpack/lib/action_controller/url_rewriter.rb4
-rw-r--r--actionpack/test/controller/url_test.rb38
3 files changed, 35 insertions, 9 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index a2dd1aab98..f1a24dc3fa 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -1,6 +1,6 @@
*SVN*
-* Fixed url rewriter confusion when the controller name was a substring of the controller_prefix
+* Fixed url rewriter confusion when the controller or action name was a substring of the controller_prefix or action_prefix
* Added conditional layouts like <tt>layout "weblog_standard", :except => :rss</tt> #452 [Marcel Molina]
diff --git a/actionpack/lib/action_controller/url_rewriter.rb b/actionpack/lib/action_controller/url_rewriter.rb
index 1ff172e8ad..7bf9015b37 100644
--- a/actionpack/lib/action_controller/url_rewriter.rb
+++ b/actionpack/lib/action_controller/url_rewriter.rb
@@ -49,7 +49,7 @@ module ActionController
def rewrite_path(path, options)
include_id_in_path_params(options)
-
+
path = rewrite_action(path, options) if options[:action] || options[:action_prefix]
path = rewrite_path_params(path, options) if options[:path_params]
path = rewrite_controller(path, options) if options[:controller] || options[:controller_prefix]
@@ -86,7 +86,7 @@ module ActionController
# don't tell action_name about our little boo-boo
path = path.sub(action_prefix, action_name(options, nil))
elsif action_prefix && !action_prefix.empty?
- path = path.sub(action_prefix, action_name(options, action_prefix))
+ path = path.sub(%r(/#{action_prefix}/?), "/" + action_name(options, action_prefix))
else
path = path.sub(%r(#{@controller}/?$), @controller + "/" + action_name(options)) # " ruby-mode
end
diff --git a/actionpack/test/controller/url_test.rb b/actionpack/test/controller/url_test.rb
index 93c8eb464d..b595b1c25c 100644
--- a/actionpack/test/controller/url_test.rb
+++ b/actionpack/test/controller/url_test.rb
@@ -12,6 +12,15 @@ class MockRequest
end
end
+class UrlMockFactory
+ def self.create(path, parameters)
+ ActionController::UrlRewriter.new(
+ MockRequest.new("http://", "example.com", 80, path, parameters),
+ parameters["controller"], parameters["action"]
+ )
+ end
+end
+
class UrlTest < Test::Unit::TestCase
def setup
@library_url = ActionController::UrlRewriter.new(MockRequest.new(
@@ -408,12 +417,29 @@ class UrlTest < Test::Unit::TestCase
end
def test_rewriting_on_similar_fragments
- url = ActionController::UrlRewriter.new(
- MockRequest.new(
- "http://", "example.com", 80, "/advertisements/advert/",
- {"controller"=>"advert", "action"=>"index"}
- ), "advert", "index"
- )
+ url = UrlMockFactory.create("/advertisements/advert/", {"controller"=>"advert", "action"=>"index"})
assert_equal("http://example.com/advertisements/advert/news", url.rewrite(:action => 'news'))
end
+
+ def test_rewriting_on_similar_fragments_with_action_prefixes
+ url = UrlMockFactory.create(
+ "/clients/prall/1/msg/all/",
+ { "category_name"=>"all", "client_name"=>"prall", "action"=>"index", "controller"=>"msg", "project_name"=>"1"}
+ )
+
+ assert_equal(
+ "http://example.com/clients/prall/1/msg/all/new",
+ url.rewrite({ :controller => "msg", :action_prefix => "all", :action => "new" })
+ )
+
+ url = UrlMockFactory.create(
+ "/clients/prall/1/msg/all/",
+ { "category_name"=>"all", "client_name"=>"prall", "action"=>"index", "controller"=>"msg", "project_name"=>"1"}
+ )
+
+ assert_equal(
+ "http://example.com/clients/prall/1/msg/allous/new",
+ url.rewrite({ :controller => "msg", :action_prefix => "allous", :action => "new" })
+ )
+ end
end