diff --git a/cli/command/image/build/internal/urlutil/urlutil.go b/cli/command/image/build/internal/urlutil/urlutil.go index b1cf47ce316b..c55f05a394df 100644 --- a/cli/command/image/build/internal/urlutil/urlutil.go +++ b/cli/command/image/build/internal/urlutil/urlutil.go @@ -19,7 +19,8 @@ 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 { - return strings.HasPrefix(str, "https://") || strings.HasPrefix(str, "http://") + return (len(str) >= 8 && strings.EqualFold(str[:8], "https://")) || + (len(str) >= 7 && strings.EqualFold(str[:7], "http://")) } // IsGitURL returns true if the provided str is a remote git repository "URL". diff --git a/cli/command/image/build/internal/urlutil/urlutil_test.go b/cli/command/image/build/internal/urlutil/urlutil_test.go index f6d0a35de3ec..17926cbc8391 100644 --- a/cli/command/image/build/internal/urlutil/urlutil_test.go +++ b/cli/command/image/build/internal/urlutil/urlutil_test.go @@ -40,3 +40,12 @@ func TestIsGIT(t *testing.T) { } } } + + +func TestIsURLCaseInsensitive(t *testing.T) { + assert.Check(t, IsURL("HTTPS://example.com/context.tar")) + assert.Check(t, IsURL("HTTP://example.com/context.tar")) + assert.Check(t, IsURL("Http://example.com/context.tar")) + assert.Check(t, !IsURL("ftp://example.com/context.tar")) + assert.Check(t, !IsURL("http:/example.com")) +}