ruby-changes:60516
From: Samuel <ko1@a...>
Date: Thu, 26 Mar 2020 18:06:33 +0900 (JST)
Subject: [ruby-changes:60516] 844ff7ea45 (master): [ruby/uri] Simplify construction of URI instances using parser interface.
https://git.ruby-lang.org/ruby.git/commit/?id=844ff7ea45 From 844ff7ea45b79e95eaed4b725fd0cf5c33874058 Mon Sep 17 00:00:00 2001 From: Samuel Williams <samuel.williams@o...> Date: Sat, 28 Dec 2019 11:36:41 +1300 Subject: [ruby/uri] Simplify construction of URI instances using parser interface. https://github.com/ruby/uri/commit/c145017dd7 diff --git a/lib/uri/common.rb b/lib/uri/common.rb index e3ed405..799a268 100644 --- a/lib/uri/common.rb +++ b/lib/uri/common.rb @@ -146,6 +146,20 @@ module URI https://github.com/ruby/ruby/blob/trunk/lib/uri/common.rb#L146 end # + # Construct a URI instance, using the scheme to detect the appropriate class + # from +URI.scheme_list+. + # + def self.for(scheme, *arguments, default: Generic) + if scheme + uri_class = @@schemes[scheme.upcase] || default + else + uri_class = default + end + + return uri_class.new(scheme, *arguments) + end + + # # Base class for all URI exceptions. # class Error < StandardError; end diff --git a/lib/uri/rfc2396_parser.rb b/lib/uri/rfc2396_parser.rb index 556da20a..38c0c36 100644 --- a/lib/uri/rfc2396_parser.rb +++ b/lib/uri/rfc2396_parser.rb @@ -208,21 +208,9 @@ module URI https://github.com/ruby/ruby/blob/trunk/lib/uri/rfc2396_parser.rb#L208 # #=> #<URI::LDAP ldap://ldap.example.com/dc=example?user=john> # def parse(uri) - scheme, userinfo, host, port, - registry, path, opaque, query, fragment = self.split(uri) - - if scheme && URI.scheme_list.include?(scheme.upcase) - URI.scheme_list[scheme.upcase].new(scheme, userinfo, host, port, - registry, path, opaque, query, - fragment, self) - else - Generic.new(scheme, userinfo, host, port, - registry, path, opaque, query, - fragment, self) - end + URI.for(*self.split(uri), self) end - # # == Args # diff --git a/lib/uri/rfc3986_parser.rb b/lib/uri/rfc3986_parser.rb index 08539f0..49a594c 100644 --- a/lib/uri/rfc3986_parser.rb +++ b/lib/uri/rfc3986_parser.rb @@ -69,18 +69,7 @@ module URI https://github.com/ruby/ruby/blob/trunk/lib/uri/rfc3986_parser.rb#L69 end def parse(uri) # :nodoc: - scheme, userinfo, host, port, - registry, path, opaque, query, fragment = self.split(uri) - scheme_list = URI.scheme_list - if scheme && scheme_list.include?(uc = scheme.upcase) - scheme_list[uc].new(scheme, userinfo, host, port, - registry, path, opaque, query, - fragment, self) - else - Generic.new(scheme, userinfo, host, port, - registry, path, opaque, query, - fragment, self) - end + URI.for(*self.split(uri), self) end -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/