From 791b2f65f1e2f153f5f2f2ac6390ff7534653525 Mon Sep 17 00:00:00 2001 From: Aditya Gupta <59690681+adityagupta26@users.noreply.github.com> Date: Sun, 29 Nov 2026 22:37:54 +0530 Subject: [PATCH] build: match HTTP(S) URL schemes case-insensitively in urlutil.IsURL Signed-off-by: Aditya Gupta <59690681+adityagupta26@users.noreply.github.com> --- cli/command/image/build/internal/urlutil/urlutil.go | 3 ++- cli/command/image/build/internal/urlutil/urlutil_test.go | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) 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")) +}