@@ -23,6 +23,7 @@ import (
23
23
)
24
24
25
25
// SchemeMap maps URL schemes to values. The zero value is an empty map, ready for use.
26
+ // All schemes are stored and compared case-insensitively.
26
27
type SchemeMap struct {
27
28
api string
28
29
m map [string ]any
@@ -46,6 +47,7 @@ func (m *SchemeMap) Register(api, typ, scheme string, value any) {
46
47
} else if m .api != api {
47
48
panic (fmt .Errorf ("previously registered using api %q (now %q)" , m .api , api ))
48
49
}
50
+ scheme = strings .ToLower (scheme )
49
51
if _ , exists := m .m [scheme ]; exists {
50
52
panic (fmt .Errorf ("scheme %q already registered for %s.%s" , scheme , api , typ ))
51
53
}
@@ -67,7 +69,7 @@ func (m *SchemeMap) FromString(typ, urlstr string) (any, *url.URL, error) {
67
69
68
70
// FromURL looks up the value for u's scheme.
69
71
func (m * SchemeMap ) FromURL (typ string , u * url.URL ) (any , error ) {
70
- scheme := u .Scheme
72
+ scheme := strings . ToLower ( u .Scheme )
71
73
if scheme == "" {
72
74
return nil , fmt .Errorf ("open %s.%s: no scheme in URL %q" , m .api , typ , u )
73
75
}
@@ -96,10 +98,6 @@ func (m *SchemeMap) Schemes() []string {
96
98
97
99
// ValidScheme returns true iff scheme has been registered.
98
100
func (m * SchemeMap ) ValidScheme (scheme string ) bool {
99
- for s := range m .m {
100
- if scheme == s {
101
- return true
102
- }
103
- }
104
- return false
101
+ _ , exists := m .m [strings .ToLower (scheme )]
102
+ return exists
105
103
}
0 commit comments