summary refs log tree commit
diff options
context:
space:
mode:
authorKeith Duncan <keith.duncan@github.com>2014-04-10 17:00:10 +0100
committerKeith Duncan <keith.duncan@github.com>2014-04-10 17:00:10 +0100
commit430892c8c98c334d8395bc5ad173c95baf3abb9f (patch)
tree8af1f6885e90373bea27037baf26c13acc1daf87
parentce4a3959a5be68684c447ce68c626d0cc84f8c1a (diff)
downloadrack-430892c8c98c334d8395bc5ad173c95baf3abb9f.tar.gz
Fix `clean_path_info` for paths with only a slash
-rw-r--r--lib/rack/utils.rb2
-rw-r--r--test/spec_utils.rb4
2 files changed, 5 insertions, 1 deletions
diff --git a/lib/rack/utils.rb b/lib/rack/utils.rb
index 6c2bf907..9b12bf75 100644
--- a/lib/rack/utils.rb
+++ b/lib/rack/utils.rb
@@ -637,7 +637,7 @@ module Rack
         part == '..' ? clean.pop : clean << part
       end
 
-      clean.unshift '/' if parts.first.empty?
+      clean.unshift '/' if parts.empty? || parts.first.empty?
 
       ::File.join(*clean)
     end
diff --git a/test/spec_utils.rb b/test/spec_utils.rb
index c3867965..4808e988 100644
--- a/test/spec_utils.rb
+++ b/test/spec_utils.rb
@@ -403,6 +403,10 @@ describe Rack::Utils do
   should "not clean directory traversal with encoded periods" do
     Rack::Utils.clean_path_info("/%2E%2E/README").should.equal "/%2E%2E/README"
   end
+
+  should "not clean slash only paths" do
+    Rack::Utils.clean_path_info("/").should.equal "/"
+  end
 end
 
 describe Rack::Utils, "byte_range" do