@@ -41,18 +41,52 @@ def test_ractor
41
41
RUBY
42
42
end
43
43
44
+ DEFAULT_SCHEMES = [ "FILE" , "FTP" , "HTTP" , "HTTPS" , "LDAP" , "LDAPS" , "MAILTO" , "WS" , "WSS" ] . sort . freeze
45
+
44
46
def test_register_scheme
45
- assert_equal ( [ "FILE" , "FTP" , "HTTP" , "HTTPS" , "LDAP" , "LDAPS" , "MAILTO" , "WS" , "WSS" ] . sort , URI . scheme_list . keys . sort )
47
+ assert_equal ( DEFAULT_SCHEMES , URI . scheme_list . keys . sort )
46
48
47
49
foobar = Class . new ( URI ::Generic )
48
50
URI . register_scheme 'FOOBAR' , foobar
49
51
begin
50
- assert_equal ( [ "FILE" , "FTP" , "HTTP" , "HTTPS" , "LDAP" , "LDAPS" , "MAILTO" , "WS" , "WSS" , "FOOBAR" ] . sort , URI . scheme_list . keys . sort )
52
+ assert_include ( URI . scheme_list . keys , "FOOBAR" )
53
+ assert_equal foobar , URI . parse ( 'foobar://localhost' ) . class
51
54
ensure
52
55
URI . const_get ( :Schemes ) . send ( :remove_const , :FOOBAR )
53
56
end
54
57
55
- assert_equal ( [ "FILE" , "FTP" , "HTTP" , "HTTPS" , "LDAP" , "LDAPS" , "MAILTO" , "WS" , "WSS" ] . sort , URI . scheme_list . keys . sort )
58
+ assert_equal ( DEFAULT_SCHEMES , URI . scheme_list . keys . sort )
59
+ end
60
+
61
+ def test_register_scheme_lowercase
62
+ assert_equal ( DEFAULT_SCHEMES , URI . scheme_list . keys . sort )
63
+
64
+ foobar = Class . new ( URI ::Generic )
65
+ URI . register_scheme 'foobarlower' , foobar
66
+ begin
67
+ assert_include ( URI . scheme_list . keys , "FOOBARLOWER" )
68
+ assert_equal foobar , URI . parse ( 'foobarlower://localhost' ) . class
69
+ ensure
70
+ URI . const_get ( :Schemes ) . send ( :remove_const , :FOOBARLOWER )
71
+ end
72
+
73
+ assert_equal ( DEFAULT_SCHEMES , URI . scheme_list . keys . sort )
74
+ end
75
+
76
+ def test_register_scheme_with_symbols
77
+ # Valid schemes from https://www.iana.org/assignments/uri-schemes/uri-schemes.xhtml
78
+ some_uri_class = Class . new ( URI ::Generic )
79
+ assert_raise ( NameError ) { URI . register_scheme 'ms-search' , some_uri_class }
80
+ assert_raise ( NameError ) { URI . register_scheme 'microsoft.windows.camera' , some_uri_class }
81
+ assert_raise ( NameError ) { URI . register_scheme 'coaps+ws' , some_uri_class }
82
+
83
+ ms_search_class = Class . new ( URI ::Generic )
84
+ URI . register_scheme 'MS_SEARCH' , ms_search_class
85
+ begin
86
+ assert_equal URI ::Generic , URI . parse ( 'ms-search://localhost' ) . class
87
+ ensure
88
+ URI . const_get ( :Schemes ) . send ( :remove_const , :MS_SEARCH )
89
+ end
56
90
end
57
91
58
92
def test_regexp
0 commit comments