Skip to content

Commit

Permalink
Merge branch 'ruby:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
rm155 authored Aug 18, 2021
2 parents 71ef3a6 + bc47bf7 commit 6f7e3cf
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
7 changes: 1 addition & 6 deletions lib/uri.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,4 @@ module URI
require_relative 'uri/ldap'
require_relative 'uri/ldaps'
require_relative 'uri/mailto'

module URI
INITIAL_SCHEMES = scheme_list
private_constant :INITIAL_SCHEMES
Ractor.make_shareable(INITIAL_SCHEMES) if defined?(Ractor)
end
require_relative 'uri/ws'
8 changes: 6 additions & 2 deletions lib/uri/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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+.
Expand All @@ -87,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

Expand Down
7 changes: 7 additions & 0 deletions test/uri/test_generic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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/')
Expand Down

0 comments on commit 6f7e3cf

Please sign in to comment.