Skip to content

Commit

Permalink
fix(GODT-2201): Flag list can be empty
Browse files Browse the repository at this point in the history
  • Loading branch information
LBeernaertProton authored and jameshoulahan committed Feb 16, 2023
1 parent 9ee2b35 commit 169bd00
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
36 changes: 19 additions & 17 deletions imap/command/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,29 @@ func ParseFlagList(p *rfcparser.Parser) ([]string, error) {
return nil, err
}

{
firstFlag, err := ParseFlag(p)
if err != nil {
return nil, err
if !p.Check(rfcparser.TokenTypeRParen) {
{
firstFlag, err := ParseFlag(p)
if err != nil {
return nil, err
}
flags = append(flags, firstFlag)
}
flags = append(flags, firstFlag)
}

for {
if ok, err := p.Matches(rfcparser.TokenTypeSP); err != nil {
return nil, err
} else if !ok {
break
}
for {
if ok, err := p.Matches(rfcparser.TokenTypeSP); err != nil {
return nil, err
} else if !ok {
break
}

flag, err := ParseFlag(p)
if err != nil {
return nil, err
}
flag, err := ParseFlag(p)
if err != nil {
return nil, err
}

flags = append(flags, flag)
flags = append(flags, flag)
}
}

if err := p.Consume(rfcparser.TokenTypeRParen, "Expected ')' at end of flag list"); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion imap/command/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ func TestParser_ParseFlagList(t *testing.T) {
values := map[string][]string{
`(\Answered)`: {`\Answered`},
`(\Answered Foo \Something)`: {`\Answered`, `Foo`, `\Something`},
`()`: nil,
}

for input, expected := range values {
Expand All @@ -24,7 +25,6 @@ func TestParser_ParseFlagList(t *testing.T) {

func TestParser_ParseFlagListInvalid(t *testing.T) {
inputs := [][]byte{
[]byte(`()`),
[]byte(`(\Foo\Bar)`),
[]byte(`"(\Recent)`),
[]byte(`(\Foo )`),
Expand Down

0 comments on commit 169bd00

Please sign in to comment.