1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #16544 from schneems/schneems/death-to-dir-glob

Refactor out Dir.glob from ActionDispatch::Static
This commit is contained in:
Guillermo Iguaran 2014-08-27 14:00:37 -05:00
commit 728f2ebdb6
6 changed files with 13 additions and 20 deletions

View file

@ -21,17 +21,13 @@ module ActionDispatch
end
def match?(path)
path = unescape_path(path)
path = URI.parser.unescape(path)
return false unless path.valid_encoding?
full_path = path.empty? ? @root : File.join(@root, escape_glob_chars(path))
paths = "#{full_path}#{ext}"
paths = [path, "#{path}#{ext}", "#{path}/index#{ext}"]
matches = Dir[paths]
match = matches.detect { |m| File.file?(m) }
if match
match.sub!(@compiled_root, '')
::Rack::Utils.escape(match)
if match = paths.detect {|p| File.file?(File.join(@root, p)) }
return ::Rack::Utils.escape(match)
end
end
@ -57,18 +53,7 @@ module ActionDispatch
private
def ext
@ext ||= begin
ext = ::ActionController::Base.default_static_extension
"{,#{ext},/index#{ext}}"
end
end
def unescape_path(path)
URI.parser.unescape(path)
end
def escape_glob_chars(path)
path.gsub(/[*?{}\[\]]/, "\\\\\\&")
::ActionController::Base.default_static_extension
end
def content_type(path)

View file

@ -37,6 +37,10 @@ module StaticTests
assert_html "/foo/index.html", get("/foo")
end
def test_serves_file_with_same_name_before_index_in_directory
assert_html "/bar.html", get("/bar")
end
def test_served_static_file_with_non_english_filename
jruby_skip "Stop skipping if following bug gets fixed: " \
"http://jira.codehaus.org/browse/JRUBY-7192"

View file

@ -0,0 +1 @@
/bar.html

View file

@ -0,0 +1 @@
/bar/index.html

View file

@ -0,0 +1 @@
/bar.html

View file

@ -0,0 +1 @@
/bar/index.html