mirror of
https://github.com/helm/helm.git
synced 2026-05-28 04:35:48 -04:00
fix(version): avoid false range detection on prerelease x/X
`isVersionRange` checked for `x`/`X` across the entire version string, misclassifying exact versions like `1.0.0-fix`, `2.0.0-next`, or `1.0.0+exp` as ranges. Signed-off-by: Benoit Tigeot <benoit.tigeot@lifen.fr>
This commit is contained in:
parent
b79d7f1881
commit
740174a2b1
2 changed files with 12 additions and 1 deletions
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in a new issue