1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Prepare to release RubyGems 3.1.0 final version.

This commit is contained in:
Hiroshi SHIBATA 2019-12-13 20:19:08 +09:00
parent 26774351dc
commit 82cc2843a9
No known key found for this signature in database
GPG key ID: F9CF13417264FAC2
23 changed files with 393 additions and 142 deletions

View file

@ -0,0 +1,36 @@
# frozen_string_literal: true
##
# The UriParser handles parsing URIs.
#
class Gem::UriParser
##
# Parses the #uri, raising if it's invalid
def parse!(uri)
raise URI::InvalidURIError unless uri
# Always escape URI's to deal with potential spaces and such
# It should also be considered that source_uri may already be
# a valid URI with escaped characters. e.g. "{DESede}" is encoded
# as "%7BDESede%7D". If this is escaped again the percentage
# symbols will be escaped.
begin
URI.parse(uri)
rescue URI::InvalidURIError
URI.parse(URI::DEFAULT_PARSER.escape(uri))
end
end
##
# Parses the #uri, returning the original uri if it's invalid
def parse(uri)
parse!(uri)
rescue URI::InvalidURIError
uri
end
end