summaryrefslogtreecommitdiff
path: root/lib/rack/static.rb
diff options
context:
space:
mode:
authorArron Mabrey <arron@mabreys.com>2015-08-01 10:13:34 -0400
committerArron Mabrey <arron@mabreys.com>2015-08-01 10:13:34 -0400
commit5db439fbf200abc14148f29582e90ad6cb6590b5 (patch)
tree401a2efba6f39129632621d4167766a943567890 /lib/rack/static.rb
parent4453f50aa0d36f0fca08a19d75270c7fb28d2b74 (diff)
downloadrack-5db439fbf200abc14148f29582e90ad6cb6590b5.tar.gz
Fixes an issue where `Rack::Static` can raise "TypeError: no implicit conversion of nil into String"
This is due a bug that always incorrectly tries to append `@index` to a root path. This happens even when the "index option" is not given, thus `@index == nil`.
Diffstat (limited to 'lib/rack/static.rb')
-rw-r--r--lib/rack/static.rb8
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/rack/static.rb b/lib/rack/static.rb
index f401abeb..d9815b11 100644
--- a/lib/rack/static.rb
+++ b/lib/rack/static.rb
@@ -95,8 +95,12 @@ module Rack
@file_server = Rack::File.new(root)
end
+ def add_index_root?(path)
+ @index && path =~ /\/$/
+ end
+
def overwrite_file_path(path)
- @urls.kind_of?(Hash) && @urls.key?(path) || @index && path =~ /\/$/
+ @urls.kind_of?(Hash) && @urls.key?(path) || add_index_root?(path)
end
def route_file(path)
@@ -112,7 +116,7 @@ module Rack
if can_serve(path)
if overwrite_file_path(path)
- env[PATH_INFO] = (path =~ /\/$/ ? path + @index : @urls[path])
+ env[PATH_INFO] = (add_index_root?(path) ? path + @index : @urls[path])
elsif @gzip && env['HTTP_ACCEPT_ENCODING'] =~ /\bgzip\b/
path = env[PATH_INFO]
env[PATH_INFO] += '.gz'