Skip to content
This repository
Browse code

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
  • Loading branch information...
commit d3a8d5f93c6eee44a23f26fcb6573e77625f41b0 1 parent cb8a020
David Heinemeier Hansson authored January 12, 2005
2  actionpack/CHANGELOG
... ...
@@ -1,6 +1,6 @@
1 1
 *SVN*
2 2
 
3  
-* Fixed url rewriter confusion when the controller name was a substring of the controller_prefix
  3
+* Fixed url rewriter confusion when the controller or action name was a substring of the controller_prefix or action_prefix
4 4
 
5 5
 * Added conditional layouts like <tt>layout "weblog_standard", :except => :rss</tt> #452 [Marcel Molina]
6 6
 
4  actionpack/lib/action_controller/url_rewriter.rb
@@ -49,7 +49,7 @@ def rewrite_url(path, options)
49 49
 
50 50
       def rewrite_path(path, options)
51 51
         include_id_in_path_params(options)
52  
-      
  52
+
53 53
         path = rewrite_action(path, options)      if options[:action] || options[:action_prefix]
54 54
         path = rewrite_path_params(path, options) if options[:path_params]
55 55
         path = rewrite_controller(path, options)  if options[:controller] || options[:controller_prefix]
@@ -86,7 +86,7 @@ def rewrite_action(path, options)
86 86
             # don't tell action_name about our little boo-boo
87 87
             path = path.sub(action_prefix, action_name(options, nil))
88 88
           elsif action_prefix && !action_prefix.empty?
89  
-            path = path.sub(action_prefix, action_name(options, action_prefix))
  89
+            path = path.sub(%r(/#{action_prefix}/?), "/" + action_name(options, action_prefix))
90 90
           else
91 91
             path = path.sub(%r(#{@controller}/?$), @controller + "/" + action_name(options)) # " ruby-mode
92 92
           end
38  actionpack/test/controller/url_test.rb
@@ -12,6 +12,15 @@ def host_with_port
12 12
   end
13 13
 end
14 14
 
  15
+class UrlMockFactory
  16
+  def self.create(path, parameters)
  17
+    ActionController::UrlRewriter.new(
  18
+      MockRequest.new("http://", "example.com", 80, path, parameters), 
  19
+      parameters["controller"], parameters["action"]
  20
+    )
  21
+  end
  22
+end
  23
+
15 24
 class UrlTest < Test::Unit::TestCase
16 25
   def setup
17 26
     @library_url = ActionController::UrlRewriter.new(MockRequest.new(
@@ -408,12 +417,29 @@ def test_on_explicit_index_page # My index page is very modest, thank you...
408 417
   end
409 418
 
410 419
   def test_rewriting_on_similar_fragments
411  
-    url = ActionController::UrlRewriter.new(
412  
-      MockRequest.new(
413  
-        "http://", "example.com", 80, "/advertisements/advert/",
414  
-        {"controller"=>"advert", "action"=>"index"}
415  
-      ), "advert", "index"
416  
-    )
  420
+    url = UrlMockFactory.create("/advertisements/advert/", {"controller"=>"advert", "action"=>"index"})
417 421
     assert_equal("http://example.com/advertisements/advert/news", url.rewrite(:action => 'news'))
418 422
   end
  423
+
  424
+  def test_rewriting_on_similar_fragments_with_action_prefixes
  425
+    url = UrlMockFactory.create(
  426
+      "/clients/prall/1/msg/all/", 
  427
+      { "category_name"=>"all", "client_name"=>"prall", "action"=>"index", "controller"=>"msg", "project_name"=>"1"}
  428
+    )
  429
+
  430
+    assert_equal(
  431
+      "http://example.com/clients/prall/1/msg/all/new", 
  432
+      url.rewrite({ :controller => "msg", :action_prefix => "all", :action => "new" })
  433
+    )
  434
+
  435
+    url = UrlMockFactory.create(
  436
+      "/clients/prall/1/msg/all/", 
  437
+      { "category_name"=>"all", "client_name"=>"prall", "action"=>"index", "controller"=>"msg", "project_name"=>"1"}
  438
+    )
  439
+
  440
+    assert_equal(
  441
+      "http://example.com/clients/prall/1/msg/allous/new", 
  442
+      url.rewrite({ :controller => "msg", :action_prefix => "allous", :action => "new" })
  443
+    )
  444
+  end
419 445
 end

0 notes on commit d3a8d5f

Please sign in to comment.
Something went wrong with that request. Please try again.