Dark Mode

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

openurl: fix URL scheme handling case-insensitive #3521

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking "Sign up for GitHub", you agree to our terms of service and privacy statement. We'll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
vangent merged 1 commit into google:master from Gofastasf:fix/schemes
Feb 7, 2025
Merged

openurl: fix URL scheme handling case-insensitive #3521

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions internal/openurl/openurl.go
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
)

// SchemeMap maps URL schemes to values. The zero value is an empty map, ready for use.
// All schemes are stored and compared case-insensitively.
type SchemeMap struct {
api string
m map[string]any
Expand All @@ -46,6 +47,7 @@ func (m *SchemeMap) Register(api, typ, scheme string, value any) {
} else if m.api != api {
panic(fmt.Errorf("previously registered using api %q (now %q)", m.api, api))
}
scheme = strings.ToLower(scheme)
if _, exists := m.m[scheme]; exists {
panic(fmt.Errorf("scheme %q already registered for %s.%s", scheme, api, typ))
}
Expand All @@ -67,7 +69,7 @@ func (m *SchemeMap) FromString(typ, urlstr string) (any, *url.URL, error) {

// FromURL looks up the value for u's scheme.
func (m *SchemeMap) FromURL(typ string, u *url.URL) (any, error) {
scheme := u.Scheme
scheme := strings.ToLower(u.Scheme)
if scheme == "" {
return nil, fmt.Errorf("open %s.%s: no scheme in URL %q", m.api, typ, u)
}
Expand Down Expand Up @@ -96,10 +98,6 @@ func (m *SchemeMap) Schemes() []string {

// ValidScheme returns true iff scheme has been registered.
func (m *SchemeMap) ValidScheme(scheme string) bool {
for s := range m.m {
if scheme == s {
return true
}
}
return false
_, exists := m.m[strings.ToLower(scheme)]
return exists
}