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

Changeset 4677

Show
Ignore:
Timestamp:
08/05/06 22:12:50 (2 years ago)
Author:
ulysses
Message:

Make Routing noisy when an anchor regexp is assigned to a segment. Closes #5674

Files:

Legend:

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

    r4674 r4677  
    11*SVN* 
    22 
     3* Make Routing noisy when an anchor regexp is assigned to a segment. #5674 [francois.beausoleil@gmail.com] 
     4 
    35* Added months and years to the resolution of DateHelper#distance_of_time_in_words, such that "60 days ago" becomes "2 months ago" #5611 [pjhyett@gmail.com] 
    46 
     7>>>>>>> .r4676 
    58* Short documentation to mention use of Mime::Type.register. #5710 [choonkeat@gmail.com] 
    69 
  • trunk/actionpack/lib/action_controller/routing.rb

    r4637 r4677  
    680680        [defaults, requirements, conditions] 
    681681      end 
    682    
     682       
    683683      # Takes a hash of defaults and a hash of requirements, and assigns them to 
    684684      # the segments. Any unused requirements (which do not correspond to a segment) 
     
    695695          if segment 
    696696            raise TypeError, "#{key}: requirements on a path segment must be regular expressions" unless requirement.is_a?(Regexp) 
     697            if requirement.source =~ %r{\\A|\\Z|\\z|\^|\$} 
     698              raise ArgumentError, "Regexp anchor characters are not allowed in routing requirements: #{requirement.inspect}" 
     699            end 
    697700            segment.regexp = requirement 
    698701          else 
  • trunk/actionpack/test/controller/routing_test.rb

    r4518 r4677  
    151151    rs.draw do |map| 
    152152      map.article 'page/:year/:month/:day/:title', :controller => 'page', :action => 'show', 
    153         :year => /^\d+$/, :month => /^\d+$/, :day => /^\d+$
     153        :year => /\d+/, :month => /\d+/, :day => /\d+
    154154      map.connect ':controller/:action/:id' 
    155155    end 
     
    12171217      controller.send(:multi_url, 7, "hello", 5) 
    12181218  end 
    1219    
     1219 
    12201220  def test_draw_default_route 
    12211221    ActionController::Routing.with_controllers(['users']) do 
     
    12231223        map.connect '/:controller/:action/:id' 
    12241224      end 
    1225        
     1225 
    12261226      assert_equal 1, set.routes.size 
    12271227      route = set.routes.first 
    1228        
     1228 
    12291229      assert route.segments.last.optional? 
    1230        
     1230 
    12311231      assert_equal '/users/show/10', set.generate(:controller => 'users', :action => 'show', :id => 10) 
    12321232      assert_equal '/users/index/10', set.generate(:controller => 'users', :id => 10) 
    1233        
     1233 
    12341234      assert_equal({:controller => 'users', :action => 'index', :id => '10'}, set.recognize_path('/users/index/10')) 
    12351235      assert_equal({:controller => 'users', :action => 'index', :id => '10'}, set.recognize_path('/users/index/10/')) 
    12361236    end 
    12371237  end 
    1238    
     1238 
    12391239  def test_route_with_parameter_shell 
    12401240    ActionController::Routing.with_controllers(['users', 'pages']) do 
     
    12431243        map.connect '/:controller/:action/:id' 
    12441244      end 
    1245        
     1245 
    12461246      assert_equal({:controller => 'pages', :action => 'index'}, set.recognize_path('/pages')) 
    12471247      assert_equal({:controller => 'pages', :action => 'index'}, set.recognize_path('/pages/index')) 
    12481248      assert_equal({:controller => 'pages', :action => 'list'}, set.recognize_path('/pages/list')) 
    1249        
     1249 
    12501250      assert_equal({:controller => 'pages', :action => 'show', :id => '10'}, set.recognize_path('/pages/show/10')) 
    12511251      assert_equal({:controller => 'pages', :action => 'show', :id => '10'}, set.recognize_path('/page/10')) 
     
    12531253  end 
    12541254 
     1255  def test_route_requirements_with_anchor_chars_are_invalid 
     1256    assert_raises ArgumentError do 
     1257      set.draw do |map| 
     1258        map.connect 'page/:id', :controller => 'pages', :action => 'show', :id => /^\d+/ 
     1259      end 
     1260    end 
     1261    assert_raises ArgumentError do 
     1262      set.draw do |map| 
     1263        map.connect 'page/:id', :controller => 'pages', :action => 'show', :id => /\A\d+/ 
     1264      end 
     1265    end 
     1266    assert_raises ArgumentError do 
     1267      set.draw do |map| 
     1268        map.connect 'page/:id', :controller => 'pages', :action => 'show', :id => /\d+$/ 
     1269      end 
     1270    end 
     1271    assert_raises ArgumentError do 
     1272      set.draw do |map| 
     1273        map.connect 'page/:id', :controller => 'pages', :action => 'show', :id => /\d+\Z/ 
     1274      end 
     1275    end 
     1276    assert_raises ArgumentError do 
     1277      set.draw do |map| 
     1278        map.connect 'page/:id', :controller => 'pages', :action => 'show', :id => /\d+\z/ 
     1279      end 
     1280    end 
     1281    assert_nothing_raised do 
     1282      set.draw do |map| 
     1283        map.connect 'page/:id', :controller => 'pages', :action => 'show', :id => /\d+/, :name => /^(david|jamis)/ 
     1284      end 
     1285      assert_raises ActionController::RoutingError do 
     1286        set.generate :controller => 'pages', :action => 'show', :id => 10 
     1287      end 
     1288    end 
     1289  end 
     1290   
     1291  def test_non_path_route_requirements_match_all 
     1292    set.draw do |map| 
     1293      map.connect 'page/37s', :controller => 'pages', :action => 'show', :name => /(jamis|david)/ 
     1294    end 
     1295    assert_equal '/page/37s', set.generate(:controller => 'pages', :action => 'show', :name => 'jamis') 
     1296    assert_raises ActionController::RoutingError do 
     1297      set.generate(:controller => 'pages', :action => 'show', :name => 'not_jamis') 
     1298    end 
     1299    assert_raises ActionController::RoutingError do 
     1300      set.generate(:controller => 'pages', :action => 'show', :name => 'nor_jamis_and_david') 
     1301    end 
     1302  end 
     1303   
    12551304  def test_recognize_with_encoded_id_and_regex 
    12561305    set.draw do |map| 
    12571306      map.connect 'page/:id', :controller => 'pages', :action => 'show', :id => /[a-zA-Z0-9 ]+/ 
    12581307    end 
    1259      
     1308 
    12601309    assert_equal({:controller => 'pages', :action => 'show', :id => '10'}, set.recognize_path('/page/10')) 
    12611310    assert_equal({:controller => 'pages', :action => 'show', :id => 'hello world'}, set.recognize_path('/page/hello+world'))