Class: Gem::UriParser
- Inherits:
-
Object
- Object
- Gem::UriParser
- Defined in:
- lib/rubygems/uri_parser.rb
Overview
The UriParser handles parsing URIs.
Instance Method Summary collapse
-
#parse(uri) ⇒ Object
Parses the #uri, returning the original uri if it’s invalid.
-
#parse!(uri) ⇒ Object
Parses the #uri, raising if it’s invalid.
Instance Method Details
#parse(uri) ⇒ Object
Parses the #uri, returning the original uri if it’s invalid
30 31 32 33 34 |
# File 'lib/rubygems/uri_parser.rb', line 30 def parse(uri) parse!(uri) rescue URI::InvalidURIError uri end |
#parse!(uri) ⇒ Object
Parses the #uri, raising if it’s invalid
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/rubygems/uri_parser.rb', line 12 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 |