Skip to content

Commit

Permalink
fix the format option issue (#786)
Browse files Browse the repository at this point in the history
* to fix the format option issue

* fix the particular cases and unit test
  • Loading branch information
showjason authored Nov 6, 2023
1 parent 004887a commit c988c2a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
11 changes: 7 additions & 4 deletions pkg/config/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,17 +371,20 @@ func (s *JfsSetting) ParseFormatOptions() ([][]string, error) {
options := strings.Split(s.FormatOptions, ",")
parsedFormatOptions := make([][]string, 0, len(options))
for _, option := range options {
pair := strings.Split(strings.TrimSpace(option), "=")
if len(pair) != 1 && len(pair) != 2 {
pair := strings.SplitN(strings.TrimSpace(option), "=", 2)
if len(pair) == 2 && pair[1] == "" {
return nil, fmt.Errorf("invalid format options: %s", s.FormatOptions)
}
key := strings.TrimSpace(pair[0])
if key == "" {
// ignore empty key
continue
}
value := ""
if len(pair) == 2 {
var value string
if len(pair) == 1 {
// single key
value = ""
} else {
value = strings.TrimSpace(pair[1])
}
parsedFormatOptions = append(parsedFormatOptions, []string{key, value})
Expand Down
10 changes: 8 additions & 2 deletions pkg/config/setting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -834,10 +834,16 @@ func Test_ParseFormatOptions(t *testing.T) {
stripKeys: []string{"trash-days", "block-size"},
stripped: "--trash-days=${trash-days} --block-size=${block-size} --format-in-pod --quiet",
},

{
description: "test multiple '='",
origin: "session-token=xxx=xx=",
args: "--session-token=xxx=xx=",
stripKeys: []string{"session-token"},
stripped: "--session-token=${session-token}",
},
{
description: "test error",
origin: "trash-days=1=2",
origin: "trash-days=",
parseFail: true,
},
}
Expand Down

0 comments on commit c988c2a

Please sign in to comment.