Skip to content

Commit 6f7e3cf

Browse files
authored
Merge branch 'ruby:master' into master
2 parents 71ef3a6 + bc47bf7 commit 6f7e3cf

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

lib/uri.rb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,4 @@ module URI
100100
require_relative 'uri/ldap'
101101
require_relative 'uri/ldaps'
102102
require_relative 'uri/mailto'
103-
104-
module URI
105-
INITIAL_SCHEMES = scheme_list
106-
private_constant :INITIAL_SCHEMES
107-
Ractor.make_shareable(INITIAL_SCHEMES) if defined?(Ractor)
108-
end
103+
require_relative 'uri/ws'

lib/uri/common.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ def self.scheme_list
7979
}.to_h
8080
end
8181

82+
INITIAL_SCHEMES = scheme_list
83+
private_constant :INITIAL_SCHEMES
84+
Ractor.make_shareable(INITIAL_SCHEMES) if defined?(Ractor)
85+
8286
#
8387
# Construct a URI instance, using the scheme to detect the appropriate class
8488
# from +URI.scheme_list+.
@@ -87,8 +91,8 @@ def self.for(scheme, *arguments, default: Generic)
8791
const_name = scheme.to_s.upcase
8892

8993
uri_class = INITIAL_SCHEMES[const_name]
90-
if !uri_class && !const_name.empty? && Schemes.const_defined?(const_name, false)
91-
uri_class = Schemes.const_get(const_name, false)
94+
uri_class ||= if /\A[A-Z]\w*\z/.match?(const_name) && Schemes.const_defined?(const_name, false)
95+
Schemes.const_get(const_name, false)
9296
end
9397
uri_class ||= default
9498

test/uri/test_generic.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,13 @@ def test_parse
159159
assert_equal(nil, url.userinfo)
160160
end
161161

162+
def test_parse_scheme_with_symbols
163+
# Valid schemes from https://www.iana.org/assignments/uri-schemes/uri-schemes.xhtml
164+
assert_equal 'ms-search', URI.parse('ms-search://localhost').scheme
165+
assert_equal 'microsoft.windows.camera', URI.parse('microsoft.windows.camera://localhost').scheme
166+
assert_equal 'coaps+ws', URI.parse('coaps+ws:localhost').scheme
167+
end
168+
162169
def test_merge
163170
u1 = URI.parse('http://foo')
164171
u2 = URI.parse('http://foo/')

0 commit comments

Comments
 (0)