Commit f026fca4 authored by Antonio Terceiro's avatar Antonio Terceiro

Imported Upstream version 4.1.7

parent d63c9ab2
......@@ -7,7 +7,7 @@ def self.gem_version
module VERSION
MAJOR = 4
MINOR = 1
TINY = 6
TINY = 7
PRE = nil
STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
......
......@@ -14,7 +14,8 @@ def match?(path)
path = unescape_path(path)
return false unless path.valid_encoding?
full_path = path.empty? ? @root : File.join(@root, escape_glob_chars(path))
full_path = path.empty? ? @root : File.join(@root,
clean_path_info(escape_glob_chars(path)))
paths = "#{full_path}#{ext}"
matches = Dir[paths]
......@@ -43,6 +44,25 @@ def unescape_path(path)
def escape_glob_chars(path)
path.gsub(/[*?{}\[\]]/, "\\\\\\&")
end
private
PATH_SEPS = Regexp.union(*[::File::SEPARATOR, ::File::ALT_SEPARATOR].compact)
def clean_path_info(path_info)
parts = path_info.split PATH_SEPS
clean = []
parts.each do |part|
next if part.empty? || part == '.'
part == '..' ? clean.pop : clean << part
end
clean.unshift '/' if parts.empty? || parts.first.empty?
::File.join(*clean)
end
end
class Static
......
......@@ -7,7 +7,7 @@ def self.gem_version
module VERSION
MAJOR = 4
MINOR = 1
TINY = 6
TINY = 7
PRE = nil
STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
......
......@@ -154,7 +154,8 @@ class StaticTest < ActiveSupport::TestCase
}
def setup
@app = ActionDispatch::Static.new(DummyApp, "#{FIXTURE_LOAD_PATH}/public", "public, max-age=60")
@root = "#{FIXTURE_LOAD_PATH}/public"
@app = ActionDispatch::Static.new(DummyApp, @root, "public, max-age=60")
end
def public_path
......@@ -162,11 +163,28 @@ def public_path
end
include StaticTests
def test_custom_handler_called_when_file_is_outside_root
filename = 'shared.html.erb'
assert File.exist?(File.join(@root, '..', filename))
env = {
"REQUEST_METHOD"=>"GET",
"REQUEST_PATH"=>"/..%2F#{filename}",
"PATH_INFO"=>"/..%2F#{filename}",
"REQUEST_URI"=>"/..%2F#{filename}",
"HTTP_VERSION"=>"HTTP/1.1",
"SERVER_NAME"=>"localhost",
"SERVER_PORT"=>"8080",
"QUERY_STRING"=>""
}
assert_equal(DummyApp.call(nil), @app.call(env))
end
end
class StaticEncodingTest < StaticTest
def setup
@app = ActionDispatch::Static.new(DummyApp, "#{FIXTURE_LOAD_PATH}/公共", "public, max-age=60")
@root = "#{FIXTURE_LOAD_PATH}/公共"
@app = ActionDispatch::Static.new(DummyApp, @root, "public, max-age=60")
end
def public_path
......
......@@ -7,7 +7,7 @@ def self.gem_version
module VERSION
MAJOR = 4
MINOR = 1
TINY = 6
TINY = 7
PRE = nil
STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
......
......@@ -7,7 +7,7 @@ def self.gem_version
module VERSION
MAJOR = 4
MINOR = 1
TINY = 6
TINY = 7
PRE = nil
STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
......
......@@ -7,7 +7,7 @@ def self.gem_version
module VERSION
MAJOR = 4
MINOR = 1
TINY = 6
TINY = 7
PRE = nil
STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
......
......@@ -7,7 +7,7 @@ def self.gem_version
module VERSION
MAJOR = 4
MINOR = 1
TINY = 6
TINY = 7
PRE = nil
STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
......
......@@ -7,7 +7,7 @@ def self.gem_version
module VERSION
MAJOR = 4
MINOR = 1
TINY = 6
TINY = 7
PRE = nil
STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
......
......@@ -7,7 +7,7 @@ def self.gem_version
module VERSION
MAJOR = 4
MINOR = 1
TINY = 6
TINY = 7
PRE = nil
STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment