Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 4763

Show
Ignore:
Timestamp:
08/15/06 02:04:11 (4 years ago)
Author:
ulysses
Message:

Relax Routing's anchor pattern warning; it was preventing use of [/] inside restrictions.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/CHANGELOG

    r4762 r4763  
    11*SVN* 
     2 
     3* Relax Routing's anchor pattern warning; it was preventing use of [^/] inside restrictions. [Nicholas Seckar] 
    24 
    35* Add controller_paths variable to Routing. [Nicholas Seckar] 
  • trunk/actionpack/lib/action_controller/routing.rb

    r4762 r4763  
    682682          if segment 
    683683            raise TypeError, "#{key}: requirements on a path segment must be regular expressions" unless requirement.is_a?(Regexp) 
    684             if requirement.source =~ %r{\\A|\\Z|\\z|\^|\$
     684            if requirement.source =~ %r{\A(\\A|\^)|(\\Z|\\z|\$)\Z
    685685              raise ArgumentError, "Regexp anchor characters are not allowed in routing requirements: #{requirement.inspect}" 
    686686            end 
  • trunk/actionpack/test/controller/routing_test.rb

    r4762 r4763  
    109109    assert_equal '/admin/user/foo', rs.generate(:controller => "admin/user", :admintoken => "foo", :action => "index") 
    110110    assert_equal '/content/foo', rs.generate(:controller => "content", :action => "foo") 
     111  end 
     112 
     113  def test_route_with_regexp_and_dot 
     114    rs.draw do |map| 
     115      map.connect ':controller/:action/:file', 
     116                        :controller => /admin|user/, 
     117                        :action => /upload|download/, 
     118                        :defaults => {:file => nil}, 
     119                        :requirements => {:file => %r{[^/]+(\.[^/]+)?}} 
     120    end 
     121    # Without a file extension 
     122    assert_equal '/user/download/file', 
     123      rs.generate(:controller => "user", :action => "download", :file => "file") 
     124    assert_equal( 
     125      {:controller => "user", :action => "download", :file => "file"}, 
     126      rs.recognize_path("/user/download/file")) 
     127 
     128    # Now, let's try a file with an extension, really a dot (.) 
     129    assert_equal '/user/download/file.jpg', 
     130      rs.generate( 
     131        :controller => "user", :action => "download", :file => "file.jpg") 
     132    assert_equal( 
     133      {:controller => "user", :action => "download", :file => "file.jpg"}, 
     134      rs.recognize_path("/user/download/file.jpg")) 
    111135  end 
    112136   
     
    10101034    assert segments[7].optional? 
    10111035  end 
     1036   
     1037  def test_assign_route_options_with_anchor_chars 
     1038    segments = builder.segments_for_route_path '/cars/:action/:person/:car/' 
     1039    defaults = {:action => 'buy', :person => nil, :car => nil} 
     1040    requirements = {:person => /\w+/, :car => /^\w+$/} 
     1041     
     1042    assert_raises ArgumentError do 
     1043      route_requirements = builder.assign_route_options(segments, defaults, requirements) 
     1044    end 
     1045     
     1046    requirements[:car] = /[^\/]+/ 
     1047    route_requirements = builder.assign_route_options(segments, defaults, requirements) 
     1048  end 
     1049   
    10121050 
    10131051  def test_optional_segments_preceding_required_segments