From 5db439fbf200abc14148f29582e90ad6cb6590b5 Mon Sep 17 00:00:00 2001 From: Arron Mabrey Date: Sat, 1 Aug 2015 10:13:34 -0400 Subject: 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`. --- lib/rack/static.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'lib/rack/static.rb') 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' -- cgit v1.2.1