From e729b4fac340c83065c1aba835256959e0b765e0 Mon Sep 17 00:00:00 2001 From: PARTHIV PRATIM SAIKIA Date: Mon, 8 Dec 2025 14:44:18 +0530 Subject: [PATCH 1/2] fix: sanitize artifacthub version string for semver compliance Signed-off-by: PARTHIV PRATIM SAIKIA --- generators/artifacthub/package.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generators/artifacthub/package.go b/generators/artifacthub/package.go index c2dda39b..d0813b65 100644 --- a/generators/artifacthub/package.go +++ b/generators/artifacthub/package.go @@ -78,7 +78,7 @@ func (pkg AhPackage) GenerateComponents(group string) ([]_component.ComponentDef comp.Model.Metadata.AdditionalProperties = make(map[string]interface{}) } comp.Model.Metadata.AdditionalProperties["source_uri"] = pkg.ChartUrl - comp.Model.Version = pkg.Version + comp.Model.Version = strings.TrimPrefix(pkg.Version, "v") comp.Model.Name = pkg.Name comp.Model.Category = category.CategoryDefinition{ Name: "", From ccb3ae16584f9f4413bf0e6bcb7fd2ef5b1ac24f Mon Sep 17 00:00:00 2001 From: PARTHIV PRATIM SAIKIA Date: Mon, 8 Dec 2025 16:11:05 +0530 Subject: [PATCH 2/2] test: add unit tests for version sanitization Signed-off-by: PARTHIV PRATIM SAIKIA --- generators/artifacthub/package.go | 6 +++++- generators/artifacthub/package_test.go | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/generators/artifacthub/package.go b/generators/artifacthub/package.go index d0813b65..24409d15 100644 --- a/generators/artifacthub/package.go +++ b/generators/artifacthub/package.go @@ -78,7 +78,7 @@ func (pkg AhPackage) GenerateComponents(group string) ([]_component.ComponentDef comp.Model.Metadata.AdditionalProperties = make(map[string]interface{}) } comp.Model.Metadata.AdditionalProperties["source_uri"] = pkg.ChartUrl - comp.Model.Version = strings.TrimPrefix(pkg.Version, "v") + comp.Model.Version = pkg.sanitizedVersion() comp.Model.Name = pkg.Name comp.Model.Category = category.CategoryDefinition{ Name: "", @@ -142,6 +142,10 @@ func (pkg *AhPackage) Validator() { } +func (pkg AhPackage) sanitizedVersion() string { + return strings.TrimPrefix(pkg.Version, "v") +} + // GetAllAhHelmPackages returns a list of all AhPackages and is super slow to avoid rate limits. func GetAllAhHelmPackages() ([]AhPackage, error) { pkgs := make([]AhPackage, 0) diff --git a/generators/artifacthub/package_test.go b/generators/artifacthub/package_test.go index 34b24938..1b1a6401 100644 --- a/generators/artifacthub/package_test.go +++ b/generators/artifacthub/package_test.go @@ -71,3 +71,27 @@ func TestGetChartUrl(t *testing.T) { }) } } + +func TestVersionSanitization(t *testing.T) { + tests := []struct { + name string + input string + expected string + }{ + {"With v prefix", "v1.2.3", "1.2.3"}, + {"Without v prefix", "1.2.3", "1.2.3"}, + {"Date based", "v2022.06.14", "2022.06.14"}, + {"Empty", "", ""}, + {"Complex", "v1.0.0-beta+exp.sha.5114f85", "1.0.0-beta+exp.sha.5114f85"}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + pkg := AhPackage{Version: tt.input} + // This calls the helper method we added to package.go + if got := pkg.sanitizedVersion(); got != tt.expected { + t.Errorf("sanitizedVersion() = %v, want %v", got, tt.expected) + } + }) + } +}