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:
parent
1b08fe340e
commit
dd5ea55f62
2 changed files with 14 additions and 2 deletions
|
@ -31,6 +31,10 @@ func Parse(str string) (*Label, error) {
|
||||||
Schema: "docker",
|
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 {
|
if len(splits) >= 2 {
|
||||||
label.Schema = splits[1]
|
label.Schema = splits[1]
|
||||||
if label.Schema != SchemeHost && label.Schema != SchemeDocker && label.Schema != SchemeLXC {
|
if label.Schema != SchemeHost && label.Schema != SchemeDocker && label.Schema != SchemeLXC {
|
||||||
|
|
|
@ -63,7 +63,6 @@ func TestParse(t *testing.T) {
|
||||||
},
|
},
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
args: "label1:host",
|
args: "label1:host",
|
||||||
want: &Label{
|
want: &Label{
|
||||||
|
@ -78,12 +77,21 @@ func TestParse(t *testing.T) {
|
||||||
want: nil,
|
want: nil,
|
||||||
wantErr: true,
|
wantErr: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
args: "label1:invalidscheme",
|
args: "label1:invalidscheme",
|
||||||
want: nil,
|
want: nil,
|
||||||
wantErr: true,
|
wantErr: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
args: " label1:lxc://debian:buster",
|
||||||
|
want: nil,
|
||||||
|
wantErr: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
args: "label1 :lxc://debian:buster",
|
||||||
|
want: nil,
|
||||||
|
wantErr: true,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.args, func(t *testing.T) {
|
t.Run(tt.args, func(t *testing.T) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue