fix(package): [validator] accept supported hostless URL schemes (#395)

This commit is contained in:
Yusuf Efe authored and GitHub committed 2026-10-22 10:31:04 +08:00
1 parent 9a8b67ac85
commit 9685357daf
2 files changed
+7 -2

No files matched your search

+2 -2
View File
@@ -278,7 +278,7 @@ func IsUrl(str string) bool {
}
u, err := url.Parse(str)
if err != nil || u.Scheme == "" || u.Host == "" {
if err != nil || u.Scheme == "" {
return false
}
@@ -298,7 +298,7 @@ func IsUrl(str string) bool {
}
if u.Scheme == "file" || u.Scheme == "mailto" || u.Scheme == "data" {
return true
return u.Host != "" || u.Path != "" || u.Opaque != ""
}
host := u.Hostname()
+5
View File
@@ -436,6 +436,11 @@ func TestIsUrl(t *testing.T) {
t.Parallel()
assert := internal.NewAssert(t, "TestIsUrl")
assert.Equal(true, IsUrl("mailto:user@example.com"))
assert.Equal(true, IsUrl("file:///tmp/file.txt"))
assert.Equal(true, IsUrl("data:text/plain,hello"))
assert.Equal(false, IsUrl("mailto:"))
assert.Equal(false, IsUrl("http:/path"))
tests := []struct {
input string