Skip to content

Commit defbe23

Browse files
committed
opts: MountOpt: improve error for empty value
Before this patch: docker run --rm --mount "" busybox invalid argument "" for "--mount" flag: EOF With this patch: docker run --rm --mount "" busybox invalid argument "" for "--mount" flag: value is empty Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 028eee5 commit defbe23

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

opts/mount.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ type MountOpt struct {
2222
//
2323
//nolint:gocyclo
2424
func (m *MountOpt) Set(value string) error {
25+
value = strings.TrimSpace(value)
26+
if value == "" {
27+
return errors.New("value is empty")
28+
}
29+
2530
csvReader := csv.NewReader(strings.NewReader(value))
2631
fields, err := csvReader.Read()
2732
if err != nil {

opts/mount_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ func TestMountOptErrors(t *testing.T) {
109109
tests := []struct {
110110
doc, value, expErr string
111111
}{
112+
{
113+
doc: "empty value",
114+
expErr: "value is empty",
115+
},
112116
{
113117
doc: "missing tmpfs target",
114118
value: "type=tmpfs",

0 commit comments

Comments
 (0)