File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package opts
22
33import (
4+ "errors"
45 "fmt"
56 "strconv"
67 "strings"
@@ -17,6 +18,9 @@ type SetOpts struct {
1718// internal map, by splitting on '='.
1819func (opts * SetOpts ) Set (value string ) error {
1920 k , v , found := strings .Cut (value , "=" )
21+ if k == "" {
22+ return errors .New ("invalid option name: " + value )
23+ }
2024 var isSet bool
2125 if ! found {
2226 isSet = true
Original file line number Diff line number Diff line change @@ -24,6 +24,10 @@ func TestSetOpts(t *testing.T) {
2424
2525 err := o .Set ("feature=not-a-bool" )
2626 assert .Check (t , is .Error (err , `strconv.ParseBool: parsing "not-a-bool": invalid syntax` ))
27+ err = o .Set ("feature=" )
28+ assert .Check (t , is .Error (err , `strconv.ParseBool: parsing "": invalid syntax` ))
29+ err = o .Set ("=true" )
30+ assert .Check (t , is .Error (err , `invalid option name: =true` ))
2731}
2832
2933func TestNamedSetOpts (t * testing.T ) {
@@ -45,4 +49,8 @@ func TestNamedSetOpts(t *testing.T) {
4549
4650 err := o .Set ("feature=not-a-bool" )
4751 assert .Check (t , is .Error (err , `strconv.ParseBool: parsing "not-a-bool": invalid syntax` ))
52+ err = o .Set ("feature=" )
53+ assert .Check (t , is .Error (err , `strconv.ParseBool: parsing "": invalid syntax` ))
54+ err = o .Set ("=true" )
55+ assert .Check (t , is .Error (err , `invalid option name: =true` ))
4856}
You can’t perform that action at this time.
0 commit comments