Permalink
Browse files

Fix loading of arbitrary files in ruby's load path by traverse_to_con…

…troller.

git-svn-id: http://svn-commit.rubyonrails.org/rails/branches/stable@4456 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent bf150f0 commit a12aabc450a0ff19dfc2238b6fec9fdb09f868be @seckar seckar committed Jun 18, 2006
Showing with 27 additions and 7 deletions.
  1. +2 −0 actionpack/CHANGELOG
  2. +12 −6 actionpack/lib/action_controller/routing.rb
  3. +13 −1 actionpack/test/controller/routing_test.rb
@@ -1,5 +1,7 @@
*1.12.1* (April 6th, 2005)
+* (Hackish) Fix loading of arbitrary files in Ruby's load path by traverse_to_controller. [Nicholas Seckar]
+
* Fixed that template extensions would be cached development mode #4624 [Stefan Kaes]
* Update to Prototype 1.5.0_rc0 [Sam Stephenson]
@@ -245,13 +245,19 @@ def traverse_to_controller(segments, start_at = 0)
raise unless /^uninitialized constant .*#{controller_name}$/ =~ e.message
end
- begin
- next_mod = eval("mod::#{mod_name}", nil, __FILE__, __LINE__)
- # Check that we didn't get a module from a parent namespace
- mod = (mod == Object || next_mod.name == "#{mod.name}::#{mod_name}") ? next_mod : nil
- rescue NameError => e
- raise unless /^uninitialized constant .*#{mod_name}$/ =~ e.message
+ if mod.const_defined? mod_name
+ next_mod = mod.send(:const_get, mod_name)
+ else
+ suffix = File.join(segments[start_at..index])
+ $:.each do |base|
+ path = File.join(base, suffix)
+ next unless File.directory? path
+ next_mod = Module.new
+ mod.send(:const_set, mod_name, next_mod)
+ break
+ end
end
+ mod = next_mod
return nil unless mod
end
@@ -535,7 +535,6 @@ def test_default_route
class RouteTests < Test::Unit::TestCase
-
def route(*args)
@route = ::ActionController::Routing::Route.new(*args) unless args.empty?
return @route
@@ -972,4 +971,17 @@ def test_nil_defaults
end
end
+class ControllerComponentTest < Test::Unit::TestCase
+
+ def test_traverse_to_controller_should_not_load_arbitrary_files
+ load_path = $:.dup
+ base = File.dirname(File.dirname(File.expand_path(__FILE__)))
+ $: << File.join(base, 'fixtures')
+ assert_equal nil, ActionController::Routing::ControllerComponent.traverse_to_controller(%w(dont_load pretty please))
+ ensure
+ $:[0..-1] = load_path
+ end
+
+end
+
end

0 comments on commit a12aabc

Please sign in to comment.