Skip to content

Commit 9620e41

Browse files
committed
opts: MountOpt: improve validation for whitespace in options
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent e888a6e commit 9620e41

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

opts/mount.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ func (m *MountOpt) Set(value string) error {
7979

8080
for _, field := range fields {
8181
key, val, ok := strings.Cut(field, "=")
82+
if k := strings.TrimSpace(key); k != key {
83+
return fmt.Errorf("invalid option '%s' in '%s': option should not have whitespace", k, field)
84+
}
8285

8386
// TODO(thaJeztah): these options should not be case-insensitive.
8487
key = strings.ToLower(key)
@@ -167,7 +170,7 @@ func (m *MountOpt) Set(value string) error {
167170
}
168171
tmpfsOptions().Mode = os.FileMode(ui64)
169172
default:
170-
return fmt.Errorf("unexpected key '%s' in '%s'", key, field)
173+
return fmt.Errorf("unknown option '%s' in '%s'", key, field)
171174
}
172175
}
173176

opts/mount_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,17 +116,17 @@ func TestMountOptErrors(t *testing.T) {
116116
{
117117
doc: "invalid key=value",
118118
value: "type=volume,target=/foo,bogus=foo",
119-
expErr: "unexpected key 'bogus' in 'bogus=foo'",
119+
expErr: "unknown option 'bogus' in 'bogus=foo'",
120120
},
121121
{
122122
doc: "invalid key with leading whitespace",
123123
value: "type=volume, src=/foo,target=/foo",
124-
expErr: "unexpected key ' src' in ' src=/foo'",
124+
expErr: "invalid option 'src' in ' src=/foo': option should not have whitespace",
125125
},
126126
{
127127
doc: "invalid key with trailing whitespace",
128128
value: "type=volume,src =/foo,target=/foo",
129-
expErr: "unexpected key 'src ' in 'src =/foo'",
129+
expErr: "invalid option 'src' in 'src =/foo': option should not have whitespace",
130130
},
131131
{
132132
doc: "missing value",

0 commit comments

Comments
 (0)