diff options
author | Guillermo Iguaran <guilleiguaran@gmail.com> | 2014-08-27 14:00:37 -0500 |
---|---|---|
committer | Guillermo Iguaran <guilleiguaran@gmail.com> | 2014-08-27 14:00:37 -0500 |
commit | 728f2ebdb6b6f73587e67cd7afb718920bbce2fd (patch) | |
tree | a5e04e8b52c47c007dee4861c5f26383674ff9d7 /actionpack/lib/action_dispatch | |
parent | 5bcd5a32abf14b371424131dce819139de09c74c (diff) | |
parent | 0b1a87f73cca3da23b65f3dfb19daeac436ab2ee (diff) | |
download | rails-728f2ebdb6b6f73587e67cd7afb718920bbce2fd.tar.gz rails-728f2ebdb6b6f73587e67cd7afb718920bbce2fd.tar.bz2 rails-728f2ebdb6b6f73587e67cd7afb718920bbce2fd.zip |
Merge pull request #16544 from schneems/schneems/death-to-dir-glob
Refactor out Dir.glob from ActionDispatch::Static
Diffstat (limited to 'actionpack/lib/action_dispatch')
-rw-r--r-- | actionpack/lib/action_dispatch/middleware/static.rb | 25 |
1 files changed, 5 insertions, 20 deletions
diff --git a/actionpack/lib/action_dispatch/middleware/static.rb b/actionpack/lib/action_dispatch/middleware/static.rb index 0733132277..e66c21ef85 100644 --- a/actionpack/lib/action_dispatch/middleware/static.rb +++ b/actionpack/lib/action_dispatch/middleware/static.rb @@ -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) |