diff options
author | Aaron Patterson <tenderlove@github.com> | 2019-01-15 10:18:31 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-15 10:18:31 -0800 |
commit | 0a92893d5442496e4642231bad2d80a1ab84d5e0 (patch) | |
tree | be2c061e3788e4d2d386bc2f4ecaa1b7d8e615f5 | |
parent | 102b62027f417e8cbc8466fe88f6b7d6f2938acb (diff) | |
parent | 8f85307711ca5e7a4729641fda1552890ffa129a (diff) | |
download | rack-0a92893d5442496e4642231bad2d80a1ab84d5e0.tar.gz |
Merge pull request #1318 from rosenfeld/expand_root_path
Expands the root path in Rack::Static upon initialization
-rw-r--r-- | lib/rack/file.rb | 2 | ||||
-rw-r--r-- | test/spec_static.rb | 10 |
2 files changed, 11 insertions, 1 deletions
diff --git a/lib/rack/file.rb b/lib/rack/file.rb index 403040b6..425c1d38 100644 --- a/lib/rack/file.rb +++ b/lib/rack/file.rb @@ -22,7 +22,7 @@ module Rack attr_reader :root def initialize(root, headers = {}, default_mime = 'text/plain') - @root = root + @root = ::File.expand_path root @headers = headers @default_mime = default_mime @head = Rack::Head.new(lambda { |env| get env }) diff --git a/test/spec_static.rb b/test/spec_static.rb index 5cf7f7f6..7c510bf6 100644 --- a/test/spec_static.rb +++ b/test/spec_static.rb @@ -195,4 +195,14 @@ describe Rack::Static do res.headers['Cache-Control'].must_equal 'public, max-age=42' end + it "expands the root path upon the middleware initialization" do + relative_path = STATIC_OPTIONS[:root].sub("#{Dir.pwd}/", '') + opts = { urls: [""], root: relative_path, index: 'index.html' } + request = Rack::MockRequest.new(static(DummyApp.new, opts)) + Dir.chdir '..' do + res = request.get("") + res.must_be :ok? + res.body.must_match(/index!/) + end + end end |