use `Rack::Utils.unescape_path` to unescape paths

Escaping and unescaping paths is different than query parameters, and we
need to respect that.  This commit uses the new method in Rack to escape
and unescape paths.  Fixes #11816
This commit is contained in:
Aaron Patterson 2015-09-04 14:43:46 -07:00
parent 451b954c2f
commit e25fdad2f1
2 changed files with 4 additions and 4 deletions

View File

@ -29,7 +29,7 @@ GIT
GIT GIT
remote: git://github.com/rack/rack.git remote: git://github.com/rack/rack.git
revision: 6c4160b8c5173299f4b49ea2c9e4aab76f6b9054 revision: 4080d56bb30f26a2f09053de702896104b5fb64d
branch: master branch: master
specs: specs:
rack (2.0.0.alpha) rack (2.0.0.alpha)

View File

@ -28,7 +28,7 @@ module ActionDispatch
# Used by the `Static` class to check the existence of a valid file # Used by the `Static` class to check the existence of a valid file
# in the server's `public/` directory (see Static#call). # in the server's `public/` directory (see Static#call).
def match?(path) def match?(path)
path = URI.parser.unescape(path) path = ::Rack::Utils.unescape_path path
return false unless path.valid_encoding? return false unless path.valid_encoding?
path = Rack::Utils.clean_path_info path path = Rack::Utils.clean_path_info path
@ -43,7 +43,7 @@ module ActionDispatch
end end
} }
return ::Rack::Utils.escape(match) return ::Rack::Utils.escape_path(match)
end end
end end
@ -90,7 +90,7 @@ module ActionDispatch
def gzip_file_path(path) def gzip_file_path(path)
can_gzip_mime = content_type(path) =~ /\A(?:text\/|application\/javascript)/ can_gzip_mime = content_type(path) =~ /\A(?:text\/|application\/javascript)/
gzip_path = "#{path}.gz" gzip_path = "#{path}.gz"
if can_gzip_mime && File.exist?(File.join(@root, ::Rack::Utils.unescape(gzip_path))) if can_gzip_mime && File.exist?(File.join(@root, ::Rack::Utils.unescape_path(gzip_path)))
gzip_path gzip_path
else else
false false