From 889c89ec79fc4ee1eaff0aba597cff40119e96b9 Mon Sep 17 00:00:00 2001 From: Rickard von Essen Date: Wed, 15 Aug 2018 15:27:00 +0200 Subject: [PATCH] Validate tags --- builder/digitalocean/config.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/builder/digitalocean/config.go b/builder/digitalocean/config.go index bb4175972..19c802c4b 100644 --- a/builder/digitalocean/config.go +++ b/builder/digitalocean/config.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" "os" + "regexp" "time" "github.com/hashicorp/packer/common" @@ -125,6 +126,13 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) { if c.Tags == nil { c.Tags = make([]string, 0) } + tagRe := regexp.MustCompile("^[[:alnum:]:_-]{1,255}$") + + for _, t := range c.Tags { + if !tagRe.MatchString(t) { + errs = packer.MultiErrorAppend(errs, errors.New(fmt.Sprintf("invalid tag: %s", t))) + } + } if errs != nil && len(errs.Errors) > 0 { return nil, nil, errs