Skip to content

Commit

Permalink
Fix ActiveStorage use-case and add test case. Fixes #1464.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Jan 10, 2020
1 parent 327a865 commit db92251
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rack/files.rb
Expand Up @@ -22,7 +22,7 @@ class Files
attr_reader :root

def initialize(root, headers = {}, default_mime = 'text/plain')
@root = ::File.expand_path root
@root = (::File.expand_path(root) if root)
@headers = headers
@default_mime = default_mime
@head = Rack::Head.new(lambda { |env| get env })
Expand Down
14 changes: 14 additions & 0 deletions test/spec_files.rb
Expand Up @@ -12,6 +12,20 @@ def files(*args)
Rack::Lint.new Rack::Files.new(*args)
end

it "can be used without root" do
# https://github.com/rack/rack/issues/1464

app = Rack::Files.new(nil)

request = Rack::Request.new(
Rack::MockRequest.env_for("/cgi/test")
)

file_path = File.expand_path("cgi/test", __dir__)
status, headers, body = app.serving(request, file_path)
assert_equal 200, status
end

it 'serves files with + in the file name' do
Dir.mktmpdir do |dir|
File.write File.join(dir, "you+me.txt"), "hello world"
Expand Down

0 comments on commit db92251

Please sign in to comment.