1
0
Fork 0
mirror of https://code.forgejo.org/forgejo/runner.git synced 2025-08-26 18:20:59 +00:00

fix!: validate runner labels aren't padded with spaces

This commit is contained in:
Mathieu Fenniak 2025-08-08 20:53:30 -06:00
parent 1b08fe340e
commit dd5ea55f62
2 changed files with 14 additions and 2 deletions

View file

@ -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 {

View file

@ -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) {