Skip to content

Commit

Permalink
use Rack::Utils.unescape_path to unescape path_info
Browse files Browse the repository at this point in the history
Unescaping paths is different from unescaping query parameters.  This
commit changes the unescape to use the URI parser to unescape the path,
which leaves `+` as `+`.

Fixes #265
References rails/rails#11816
  • Loading branch information
tenderlove committed Sep 4, 2015
1 parent 978eb9b commit 568cf72
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
6 changes: 6 additions & 0 deletions HISTORY.md
@@ -1,3 +1,9 @@
Fri Sep 4 14:15:32 2015 Aaron Patterson <tenderlove@ruby-lang.org>

* Files and directories with + in the name are served correctly.
Rather than unescaping paths like a form, we unescape with a URI
parser using `Rack::Utils.unescape_path`. Fixes #265

Thu Aug 27 15:43:48 2015 Aaron Patterson <tenderlove@ruby-lang.org>

* Tempfiles are automatically closed in the case that there were too
Expand Down
2 changes: 1 addition & 1 deletion lib/rack/file.rb
Expand Up @@ -30,7 +30,7 @@ def call(env)
return fail(405, "Method Not Allowed", {'Allow' => ALLOW_HEADER})
end

path_info = Utils.unescape request.path_info
path_info = Utils.unescape_path request.path_info
clean_path_info = Utils.clean_path_info(path_info)

path = ::File.join(@root, clean_path_info)
Expand Down
15 changes: 15 additions & 0 deletions test/spec_file.rb
Expand Up @@ -10,6 +10,21 @@ def file(*args)
Rack::Lint.new Rack::File.new(*args)
end

it 'serves files with + in the file name' do
Dir.mktmpdir do |dir|
File.write File.join(dir, "you+me.txt"), "hello world"
app = file(dir)
env = Rack::MockRequest.env_for("/you+me.txt")
status,_,body = app.call env

assert_equal 200, status

str = ''
body.each { |x| str << x }
assert_match "hello world", str
end
end

it "serve files" do
res = Rack::MockRequest.new(file(DOCROOT)).get("/cgi/test")

Expand Down

0 comments on commit 568cf72

Please sign in to comment.