diff --git a/internal/pkg/labels/labels.go b/internal/pkg/labels/labels.go index 7befaf42..e256964a 100644 --- a/internal/pkg/labels/labels.go +++ b/internal/pkg/labels/labels.go @@ -31,6 +31,10 @@ func Parse(str string) (*Label, error) { Schema: "docker", } + if strings.TrimSpace(label.Name) != label.Name { + return nil, fmt.Errorf("invalid label %q: starting or ending with a space is invalid", label.Name) + } + if len(splits) >= 2 { label.Schema = splits[1] if label.Schema != SchemeHost && label.Schema != SchemeDocker && label.Schema != SchemeLXC { diff --git a/internal/pkg/labels/labels_test.go b/internal/pkg/labels/labels_test.go index db2f0adf..bf798fa2 100644 --- a/internal/pkg/labels/labels_test.go +++ b/internal/pkg/labels/labels_test.go @@ -63,7 +63,6 @@ func TestParse(t *testing.T) { }, wantErr: false, }, - { args: "label1:host", want: &Label{ @@ -78,12 +77,21 @@ func TestParse(t *testing.T) { want: nil, wantErr: true, }, - { args: "label1:invalidscheme", want: nil, wantErr: true, }, + { + args: " label1:lxc://debian:buster", + want: nil, + wantErr: true, + }, + { + args: "label1 :lxc://debian:buster", + want: nil, + wantErr: true, + }, } for _, tt := range tests { t.Run(tt.args, func(t *testing.T) {