From 169bd00e1ae09f7933b1d91dfe501e82f7a56147 Mon Sep 17 00:00:00 2001 From: Leander Beernaert Date: Thu, 16 Feb 2023 11:01:44 +0100 Subject: [PATCH] fix(GODT-2201): Flag list can be empty --- imap/command/flags.go | 36 +++++++++++++++++++----------------- imap/command/flags_test.go | 2 +- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/imap/command/flags.go b/imap/command/flags.go index 28706cad..60ac2cb6 100644 --- a/imap/command/flags.go +++ b/imap/command/flags.go @@ -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 { diff --git a/imap/command/flags_test.go b/imap/command/flags_test.go index 63a2b337..bbc2184b 100644 --- a/imap/command/flags_test.go +++ b/imap/command/flags_test.go @@ -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 { @@ -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 )`),