diff --git a/pkg/repo/v1/index.go b/pkg/repo/v1/index.go index 1ed7c32b6..f9829ec7f 100644 --- a/pkg/repo/v1/index.go +++ b/pkg/repo/v1/index.go @@ -178,7 +178,14 @@ func (i IndexFile) SortEntries() { // isVersionRange checks if the version string is a range constraint (e.g., "^1", "~1.10") // rather than an exact version (e.g., "1.10.0"). func isVersionRange(version string) bool { - return strings.ContainsAny(version, "^~<>=!*xX") || strings.Contains(version, "||") || strings.Contains(version, " - ") + if strings.ContainsAny(version, "^~<>=!*") || strings.Contains(version, "||") || strings.Contains(version, " - ") { + return true + } + core := version + if idx := strings.IndexAny(version, "-+"); idx != -1 { + core = version[:idx] + } + return strings.ContainsAny(core, "xX") } // Get returns the ChartVersion for the given name. diff --git a/pkg/repo/v1/index_test.go b/pkg/repo/v1/index_test.go index 7a3120c89..a86efe1e3 100644 --- a/pkg/repo/v1/index_test.go +++ b/pkg/repo/v1/index_test.go @@ -745,6 +745,10 @@ func TestIsVersionRange(t *testing.T) { {"1.0.0 - 2.0.0", true}, {"^1.0.0 || ^2.0.0", true}, {">=1.0.0 <2.0.0", true}, + // Exact versions with 'x'/'X' in prerelease or build metadata + {"1.0.0-fix", false}, + {"2.0.0-next", false}, + {"1.0.0+exp", false}, } for _, tt := range tests {