diff --git a/cli/command/image/build/internal/urlutil/urlutil.go b/cli/command/image/build/internal/urlutil/urlutil.go index b1cf47ce316b..11f02f2a0f91 100644 --- a/cli/command/image/build/internal/urlutil/urlutil.go +++ b/cli/command/image/build/internal/urlutil/urlutil.go @@ -19,6 +19,7 @@ var urlPathWithFragmentSuffix = lazyregexp.New(`\.git(?:#.+)?$`) // has a http:// or https:// scheme. No validation is performed to verify if the // URL is well-formed. func IsURL(str string) bool { + str = strings.ToLower(str) return strings.HasPrefix(str, "https://") || strings.HasPrefix(str, "http://") } diff --git a/cli/command/image/build/internal/urlutil/urlutil_test.go b/cli/command/image/build/internal/urlutil/urlutil_test.go index f6d0a35de3ec..7ad0f5a41b0f 100644 --- a/cli/command/image/build/internal/urlutil/urlutil_test.go +++ b/cli/command/image/build/internal/urlutil/urlutil_test.go @@ -40,3 +40,22 @@ func TestIsGIT(t *testing.T) { } } } + +func TestIsURL(t *testing.T) { + tests := []struct { + url string + want bool + }{ + {"https://example.com/context.tar", true}, + {"http://example.com/context.tar", true}, + {"HTTPS://example.com/context.tar", true}, + {"HTTP://example.com/context.tar", true}, + {"/tmp/context.tar", false}, + } + + for _, tt := range tests { + if got := IsURL(tt.url); got != tt.want { + t.Errorf("IsURL(%q) = %t, want %t", tt.url, got, tt.want) + } + } +}