summary refs log tree commit
path: root/lib/rack/request.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rack/request.rb')
-rw-r--r--lib/rack/request.rb11
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/rack/request.rb b/lib/rack/request.rb
index 951fe8cb..4ffc1972 100644
--- a/lib/rack/request.rb
+++ b/lib/rack/request.rb
@@ -496,11 +496,18 @@ module Rack
       def strip_port(ip_address)
         # IPv6 format with optional port: "[2001:db8:cafe::17]:47011"
         # returns: "2001:db8:cafe::17"
-        return ip_address.gsub(/(^\[|\]:\d+$)/, '') if ip_address.include?('[')
+        sep_start = ip_address.index('[')
+        sep_end = ip_address.index(']')
+        if (sep_start && sep_end)
+          return ip_address[sep_start + 1, sep_end - 1]
+        end
 
         # IPv4 format with optional port: "192.0.2.43:47011"
         # returns: "192.0.2.43"
-        return ip_address.gsub(/:\d+$/, '') if ip_address.count(':') == 1
+        sep = ip_address.index(':')
+        if (sep && ip_address.count(':') == 1)
+          return ip_address[0, sep]
+        end
 
         ip_address
       end