Skip to content

Commit

Permalink
feat: allow special char in repo name
Browse files Browse the repository at this point in the history
  • Loading branch information
gaelreyrol committed Feb 28, 2025
1 parent d2fa103 commit f655632
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
7 changes: 4 additions & 3 deletions pkg/helm/charts.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import (
)

var (
// https://regex101.com/r/7xFFtU/3
chartExp = regexp.MustCompile(`^(?P<chart>\w+\/.+)@(?P<version>[^:\n\s]+)(?:\:(?P<path>[\w-. ]+))?$`)
repoExp = regexp.MustCompile(`^\w+$`)
// https://regex101.com/r/9m42pQ/1
chartExp = regexp.MustCompile(`^(?P<chart>[\w+-\/.]+)@(?P<version>[^:\n\s]+)(?:\:(?P<path>[\w-. ]+))?$`)
// https://regex101.com/r/xoAx8c/1
repoExp = regexp.MustCompile(`^[\w-]+$`)
)

// LoadChartfile opens a Chartfile tree
Expand Down
16 changes: 10 additions & 6 deletions pkg/helm/charts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ func TestParseReq(t *testing.T) {
input: "https://helm.releases.hashicorp.com/[email protected]",
err: errors.New("not of form 'repo/chart@version(:path)' where repo contains no special characters"),
},
{
name: "repo-with-special-chars",
input: "with-dashes/[email protected]",
expected: &Requirement{
Chart: "with-dashes/package",
Version: "1.0.0",
Directory: "",
},
},
}

for _, tc := range testCases {
Expand All @@ -68,14 +77,9 @@ func TestAddRepos(t *testing.T) {
err = c.AddRepos(
Repo{Name: "foo", URL: "https://foo.com"},
Repo{Name: "foo2", URL: "https://foo2.com"},
)
assert.NoError(t, err)

// Only \w characters are allowed in repo names
err = c.AddRepos(
Repo{Name: "with-dashes", URL: "https://foo.com"},
)
assert.EqualError(t, err, "1 Repo(s) were skipped. Please check above logs for details")
assert.NoError(t, err)

err = c.AddRepos(
Repo{Name: "foo", URL: "https://foo.com"},
Expand Down

0 comments on commit f655632

Please sign in to comment.