Reject v-versions

Signed-off-by: MrJack <36191829+biagiopietro@users.noreply.github.com>
This commit is contained in:
MrJack 2026-02-17 17:04:21 +01:00
parent ccf02f366e
commit 8441036b07
2 changed files with 17 additions and 12 deletions

View file

@ -41,7 +41,7 @@ An exact semver version can be supplied per-plugin using the @version syntax:
helm plugin update myplugin@1.2.3 otherplugin@2.0.0
helm plugin update myplugin@v1.0.0
Range constraints (e.g. ~1.2, ^1.0.0, >=1.0.0) are not supported.
Range constraints (e.g. ~1.2, ^1.0.0, >=1.0.0, v1.0.0) are not supported.
If no version is given for a plugin it is updated to the latest version:
@ -85,8 +85,8 @@ func (o *pluginUpdateOptions) complete(args []string) error {
return fmt.Errorf("plugin %q specified more than once", name)
}
if version != "" {
if _, err := semver.NewVersion(version); err != nil {
return fmt.Errorf("invalid version %q for plugin %q: must be an exact version (e.g. 1.2.3 or v1.2.3)", version, name)
if _, err := semver.StrictNewVersion(version); err != nil {
return fmt.Errorf("invalid version %q for plugin %q: must be an exact semver version (e.g. 1.2.3); the \"v\" prefix is not allowed", version, name)
}
}
o.plugins[name] = version

View file

@ -80,8 +80,8 @@ func TestPluginUpdateComplete(t *testing.T) {
},
{
name: "multiple plugins each with different exact versions",
args: []string{"plugin-a@v1.2.3", "plugin-b@2.0.0", "plugin-c@3.0.0"},
wantPlugins: map[string]string{"plugin-a": "v1.2.3", "plugin-b": "2.0.0", "plugin-c": "3.0.0"},
args: []string{"plugin-a@1.2.3", "plugin-b@2.0.0", "plugin-c@3.0.0"},
wantPlugins: map[string]string{"plugin-a": "1.2.3", "plugin-b": "2.0.0", "plugin-c": "3.0.0"},
},
{
name: "multiple plugins mixed versions",
@ -103,40 +103,45 @@ func TestPluginUpdateComplete(t *testing.T) {
args: []string{"@1.0.0"},
wantErr: `invalid plugin reference "@1.0.0": plugin name must not be empty`,
},
{
name: "v-prefixed version rejected",
args: []string{"myplugin@v1.2.3"},
wantErr: `invalid version "v1.2.3" for plugin "myplugin": must be an exact semver version (e.g. 1.2.3); the "v" prefix is not allowed`,
},
{
name: "tilde range version rejected",
args: []string{"myplugin@~1.2"},
wantErr: `invalid version "~1.2" for plugin "myplugin": must be an exact version (e.g. 1.2.3 or v1.2.3)`,
wantErr: `invalid version "~1.2" for plugin "myplugin": must be an exact semver version (e.g. 1.2.3); the "v" prefix is not allowed`,
},
{
name: "caret range version rejected",
args: []string{"myplugin@^1.2.3"},
wantErr: `invalid version "^1.2.3" for plugin "myplugin": must be an exact version (e.g. 1.2.3 or v1.2.3)`,
wantErr: `invalid version "^1.2.3" for plugin "myplugin": must be an exact semver version (e.g. 1.2.3); the "v" prefix is not allowed`,
},
{
name: "gte constraint rejected",
args: []string{"myplugin@>=1.0.0"},
wantErr: `invalid version ">=1.0.0" for plugin "myplugin": must be an exact version (e.g. 1.2.3 or v1.2.3)`,
wantErr: `invalid version ">=1.0.0" for plugin "myplugin": must be an exact semver version (e.g. 1.2.3); the "v" prefix is not allowed`,
},
{
name: "wildcard version rejected",
args: []string{"myplugin@1.x"},
wantErr: `invalid version "1.x" for plugin "myplugin": must be an exact version (e.g. 1.2.3 or v1.2.3)`,
wantErr: `invalid version "1.x" for plugin "myplugin": must be an exact semver version (e.g. 1.2.3); the "v" prefix is not allowed`,
},
{
name: "range constraint rejected",
args: []string{"myplugin@>=1.0.0, <2.0.0"},
wantErr: `invalid version ">=1.0.0, <2.0.0" for plugin "myplugin": must be an exact version (e.g. 1.2.3 or v1.2.3)`,
wantErr: `invalid version ">=1.0.0, <2.0.0" for plugin "myplugin": must be an exact semver version (e.g. 1.2.3); the "v" prefix is not allowed`,
},
{
name: "garbage version rejected",
args: []string{"myplugin@notaversion"},
wantErr: `invalid version "notaversion" for plugin "myplugin": must be an exact version (e.g. 1.2.3 or v1.2.3)`,
wantErr: `invalid version "notaversion" for plugin "myplugin": must be an exact semver version (e.g. 1.2.3); the "v" prefix is not allowed`,
},
{
name: "range rejected among multiple plugins",
args: []string{"plugin-a@1.0.0", "plugin-b@~2.0"},
wantErr: `invalid version "~2.0" for plugin "plugin-b": must be an exact version (e.g. 1.2.3 or v1.2.3)`,
wantErr: `invalid version "~2.0" for plugin "plugin-b": must be an exact semver version (e.g. 1.2.3); the "v" prefix is not allowed`,
},
}
for _, tt := range tests {