Remove the validation of plugin version against a regex (#729)

This commit is contained in:
thecooldrop
2022-04-04 11:52:13 +02:00
committed by GitHub
parent 4fde1df8d8
commit 13f871b1e4
3 changed files with 0 additions and 27 deletions
-5
View File
@@ -23,8 +23,6 @@ func (p Plugin) String() string {
var (
// NamePattern is the plugin name regex pattern
NamePattern = regexp.MustCompile(`^[0-9a-zA-Z\-_]+$`)
// VersionPattern is the plugin version regex pattern
VersionPattern = regexp.MustCompile(`^[0-9a-zA-Z\-_+\\.]+$`)
// DownloadURLPattern is the plugin download url regex pattern
DownloadURLPattern = regexp.MustCompile(`https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)`)
)
@@ -65,9 +63,6 @@ func validatePlugin(name, version, downloadURL string) error {
if ok := NamePattern.MatchString(name); !ok {
return errors.Errorf("invalid plugin name '%s:%s', must follow pattern '%s'", name, version, NamePattern.String())
}
if ok := VersionPattern.MatchString(version); !ok {
return errors.Errorf("invalid plugin version '%s:%s', must follow pattern '%s'", name, version, VersionPattern.String())
}
if len(downloadURL) > 0 {
if ok := DownloadURLPattern.MatchString(downloadURL); !ok {
return errors.Errorf("invalid download URL '%s' for plugin name %s:%s, must follow pattern '%s'", downloadURL, name, version, DownloadURLPattern.String())
-4
View File
@@ -40,10 +40,6 @@ func TestValidatePlugin(t *testing.T) {
got := validatePlugin(validPluginName, "1074.v60e6c29b_b_44b_", "")
assert.NoError(t, got)
})
t.Run("invalid version !", func(t *testing.T) {
got := validatePlugin(validPluginName, "0.5.1!", "")
assert.Error(t, got)
})
t.Run("name 01234567890-abcdefghijklmnoprstuwxz_ABCDEFGHIJKLMNOPQRSTUVWXYZ", func(t *testing.T) {
got := validatePlugin("01234567890-abcdefghijklmnoprstuwxz_ABCDEFGHIJKLMNOPQRSTUVWXYZ", validPluginVersion, "")
assert.NoError(t, got)