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

Changeset 4456

Show
Ignore:
Timestamp:
06/18/06 04:39:42 (2 years ago)
Author:
ulysses
Message:

Fix loading of arbitrary files in ruby's load path by traverse_to_controller.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/stable/actionpack/CHANGELOG

    r4189 r4456  
    11*1.12.1* (April 6th, 2005) 
     2 
     3* (Hackish) Fix loading of arbitrary files in Ruby's load path by traverse_to_controller. [Nicholas Seckar] 
    24 
    35* Fixed that template extensions would be cached development mode #4624 [Stefan Kaes] 
  • branches/stable/actionpack/lib/action_controller/routing.rb

    r3893 r4456  
    246246            end 
    247247             
    248             begin 
    249               next_mod = eval("mod::#{mod_name}", nil, __FILE__, __LINE__) 
    250               # Check that we didn't get a module from a parent namespace 
    251               mod = (mod == Object || next_mod.name == "#{mod.name}::#{mod_name}") ? next_mod : nil 
    252             rescue NameError => e 
    253               raise unless /^uninitialized constant .*#{mod_name}$/ =~ e.message 
    254             end 
     248            if mod.const_defined? mod_name 
     249              next_mod = mod.send(:const_get, mod_name) 
     250            else 
     251              suffix = File.join(segments[start_at..index]) 
     252              $:.each do |base| 
     253                path = File.join(base, suffix) 
     254                next unless File.directory? path 
     255                next_mod = Module.new 
     256                mod.send(:const_set, mod_name, next_mod) 
     257                break 
     258              end 
     259            end 
     260            mod = next_mod 
    255261             
    256262            return nil unless mod 
  • branches/stable/actionpack/test/controller/routing_test.rb

    r3542 r4456  
    535535 
    536536class RouteTests < Test::Unit::TestCase 
    537    
    538537   
    539538  def route(*args) 
     
    973972end 
    974973 
     974class ControllerComponentTest < Test::Unit::TestCase 
     975   
     976  def test_traverse_to_controller_should_not_load_arbitrary_files 
     977    load_path = $:.dup 
     978    base = File.dirname(File.dirname(File.expand_path(__FILE__))) 
     979    $: << File.join(base, 'fixtures') 
     980    assert_equal nil, ActionController::Routing::ControllerComponent.traverse_to_controller(%w(dont_load pretty please)) 
     981  ensure 
     982    $:[0..-1] = load_path 
     983  end 
     984   
    975985end 
     986 
     987end