Backport "Regression in support for IPv6 literals in URIs with Net::HTTP"

https://github.com/ruby/ruby/commit/f01485b4ec97d6bbc462f6c7210b2499a97ce398
https://bugs.ruby-lang.org/issues/9129

https://trello.com/c/NoHDPqHH