diff --git a/actionpack/lib/action_controller/request.rb b/actionpack/lib/action_controller/request.rb index 16117a6079527b38f4ddd7ec321c968dbcca36f2..75b7c62378c13a2eac9cf7450e75595157de3e52 100755 --- a/actionpack/lib/action_controller/request.rb +++ b/actionpack/lib/action_controller/request.rb @@ -78,7 +78,7 @@ def request_uri end def path_info - env['PATH_INFO'] + (/^(.*)\.html$/ =~ env['PATH_INFO']) ? $1 : env['PATH_INFO'] end def protocol diff --git a/actionpack/test/controller/request_test.rb b/actionpack/test/controller/request_test.rb index 82a1d6bb7082638eda0f3caa5a3585707d9009d9..513828462efa50eb04b0f3f5a055ac5117a9e09b 100644 --- a/actionpack/test/controller/request_test.rb +++ b/actionpack/test/controller/request_test.rb @@ -58,6 +58,11 @@ def test_path_info @request.env["PATH_INFO"] = "/path/of/some/uri" assert_equal "/path/of/some/uri", @request.path_info assert_equal "/path/of/some/uri", @request.path + + # PATH_INFO actually has a .html suffix on many servers. But we don't want Rails to see the .html part. + @request.env["PATH_INFO"] = "/path/of/some/uri.html" + assert_equal "/path/of/some/uri", @request.path_info + assert_equal "/path/of/some/uri", @request.path end def test_host_with_port diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb index c00f5b374e31464867d5198fcfe125b7d1833b01..9518dfab90e9596037f42654708bfdbb587bc0e6 100644 --- a/activesupport/lib/active_support/dependencies.rb +++ b/activesupport/lib/active_support/dependencies.rb @@ -36,7 +36,8 @@ def clear end def require_or_load(file_name) - load? ? load("#{file_name}.rb") : require(file_name) + file_name = "#{file_name}.rb" unless ! load? || /\.rb$/ =~ file_name + load? ? load(file_name) : require(file_name) end def remove_subclasses_for(*classes) @@ -62,6 +63,7 @@ def initialize(root, path=[]) @root = root end + def root?() self.root == self end def load_paths() self.root.load_paths end # Load missing constants if possible. @@ -78,10 +80,19 @@ def const_load!(name, file_name = nil) next unless fs_path if File.directory?(fs_path) - self.const_set name, LoadingModule.new(self.root, self.path + [name]) + new_module = LoadingModule.new(self.root, self.path + [name]) + self.const_set name, new_module + if self.root? + raise NameError, "Cannot load controller module named #{name}: An object of type #{Object.const_get(name).class.to_s} already exists." \ + if Object.const_defined?(name) + Object.const_set(name, new_module) + end break elsif File.file?(fs_path) self.root.load_file!(fs_path) + + # Import the loaded constant from Object provided we are the root node. + self.const_set(name, Object.const_get(name)) if self.root? && Object.const_defined?(name) break end end @@ -109,17 +120,13 @@ def path() [] end # Load the source file at the given file path def load_file!(file_path) - begin root.module_eval(IO.read(file_path), file_path, 1) - rescue Object => exception - exception.blame_file! file_path - raise - end + require_dependency(file_path) end # Erase all items in this module def clear! constants.each do |name| - Object.send(:remove_const, name) if Object.const_defined?(name) && self.path.empty? + Object.send(:remove_const, name) if Object.const_defined?(name) self.send(:remove_const, name) end end