From fc4980dfc4d6946cea7fab2ac0fda2ba6129b9d0 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Tue, 27 Jul 2021 17:20:54 +0900 Subject: [PATCH 1/3] Added missing require for URI::WS class --- lib/uri.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/uri.rb b/lib/uri.rb index 282e82c..539365a 100644 --- a/lib/uri.rb +++ b/lib/uri.rb @@ -100,6 +100,7 @@ module URI require_relative 'uri/ldap' require_relative 'uri/ldaps' require_relative 'uri/mailto' +require_relative 'uri/ws' module URI INITIAL_SCHEMES = scheme_list From 86de79c09b82e390dce343925d31d6beb2aaed67 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Tue, 27 Jul 2021 17:34:13 +0900 Subject: [PATCH 2/3] Fix test failure for parallel testing --- lib/uri.rb | 6 ------ lib/uri/common.rb | 4 ++++ 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/uri.rb b/lib/uri.rb index 539365a..394c156 100644 --- a/lib/uri.rb +++ b/lib/uri.rb @@ -101,9 +101,3 @@ module URI require_relative 'uri/ldaps' require_relative 'uri/mailto' require_relative 'uri/ws' - -module URI - INITIAL_SCHEMES = scheme_list - private_constant :INITIAL_SCHEMES - Ractor.make_shareable(INITIAL_SCHEMES) if defined?(Ractor) -end diff --git a/lib/uri/common.rb b/lib/uri/common.rb index 2df0536..2bb13ad 100644 --- a/lib/uri/common.rb +++ b/lib/uri/common.rb @@ -79,6 +79,10 @@ def self.scheme_list }.to_h end + INITIAL_SCHEMES = scheme_list + private_constant :INITIAL_SCHEMES + Ractor.make_shareable(INITIAL_SCHEMES) if defined?(Ractor) + # # Construct a URI instance, using the scheme to detect the appropriate class # from +URI.scheme_list+. From bc47bf71df2b2e9cea09d0b2684ceac7355e42a0 Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Wed, 28 Jul 2021 00:47:16 +0200 Subject: [PATCH 3/3] Fix parsing of scheme that are invalid Ruby constant names Some symbols such as `-`, `+` or `.` are valid inside URI schemes. See: https://www.iana.org/assignments/uri-schemes/uri-schemes.xhtml --- lib/uri/common.rb | 4 ++-- test/uri/test_generic.rb | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/uri/common.rb b/lib/uri/common.rb index 2bb13ad..26b179a 100644 --- a/lib/uri/common.rb +++ b/lib/uri/common.rb @@ -91,8 +91,8 @@ def self.for(scheme, *arguments, default: Generic) const_name = scheme.to_s.upcase uri_class = INITIAL_SCHEMES[const_name] - if !uri_class && !const_name.empty? && Schemes.const_defined?(const_name, false) - uri_class = Schemes.const_get(const_name, false) + uri_class ||= if /\A[A-Z]\w*\z/.match?(const_name) && Schemes.const_defined?(const_name, false) + Schemes.const_get(const_name, false) end uri_class ||= default diff --git a/test/uri/test_generic.rb b/test/uri/test_generic.rb index d122587..fdb405e 100644 --- a/test/uri/test_generic.rb +++ b/test/uri/test_generic.rb @@ -159,6 +159,13 @@ def test_parse assert_equal(nil, url.userinfo) end + def test_parse_scheme_with_symbols + # Valid schemes from https://www.iana.org/assignments/uri-schemes/uri-schemes.xhtml + assert_equal 'ms-search', URI.parse('ms-search://localhost').scheme + assert_equal 'microsoft.windows.camera', URI.parse('microsoft.windows.camera://localhost').scheme + assert_equal 'coaps+ws', URI.parse('coaps+ws:localhost').scheme + end + def test_merge u1 = URI.parse('http://foo') u2 = URI.parse('http://foo/')