summary refs log tree commit
diff options
context:
space:
mode:
authorJames Tucker <jftucker@gmail.com>2014-07-13 15:20:44 -0700
committerJames Tucker <jftucker@gmail.com>2014-07-13 15:20:44 -0700
commitf467f1b8c21127473b9e6277608d06f9e81e101e (patch)
treea770f210876eb54b38240f52c038e932e113d577
parent4582f345bfc854556c7d5a54294193f322104f99 (diff)
downloadrack-f467f1b8c21127473b9e6277608d06f9e81e101e.tar.gz
Fix URI parsing on 1.8.7, also address perf
-rw-r--r--lib/rack/mock.rb10
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/rack/mock.rb b/lib/rack/mock.rb
index fada5bb2..3c02c1fe 100644
--- a/lib/rack/mock.rb
+++ b/lib/rack/mock.rb
@@ -77,10 +77,16 @@ module Rack
       body.close if body.respond_to?(:close)
     end
 
+    # For historical reasons, we're pinning to RFC 2396. It's easier for users
+    # and we get support from ruby 1.8 to 2.2 using this method.
+    def self.parse_uri_rfc2396(uri)
+      @parser ||= defined?(URI::RFC2396_Parser) ? URI::RFC2396_Parser.new : URI
+      @parser.parse(uri)
+    end
+
     # Return the Rack environment used for a request to +uri+.
     def self.env_for(uri="", opts={})
-      parser = URI::Parser.new
-      uri = parser.parse(uri)
+      uri = parse_uri_rfc2396(uri)
       uri.path = "/#{uri.path}" unless uri.path[0] == ?/
 
       env = DEFAULT_ENV.dup