Skip to content

Commit

Permalink
Be more lenient about spaces in RFC 2971 ID response (#774)
Browse files Browse the repository at this point in the history
  • Loading branch information
danieleggert authored Oct 24, 2024
1 parent 35583d7 commit 7328a73
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
12 changes: 11 additions & 1 deletion Sources/NIOIMAPCore/Parser/Grammar/GrammarParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -771,18 +771,28 @@ extension GrammarParser {
}

func parseIDParamsList_empty(buffer: inout ParseBuffer, tracker: StackTracker) throws -> OrderedDictionary<String, String?> {
try PL.parseFixedString("()", buffer: &buffer, tracker: tracker)
try PL.parseFixedString("(", buffer: &buffer, tracker: tracker)
_ = try PL.parseOptional(buffer: &buffer, tracker: tracker) { buffer, tracker in
try PL.parseSpaces(buffer: &buffer, tracker: tracker)
}
try PL.parseFixedString(")", buffer: &buffer, tracker: tracker)
return [:]
}

func parseIDParamsList_some(buffer: inout ParseBuffer, tracker: StackTracker) throws -> OrderedDictionary<String, String?> {
try PL.parseFixedString("(", buffer: &buffer, tracker: tracker)
_ = try PL.parseOptional(buffer: &buffer, tracker: tracker) { buffer, tracker in
try PL.parseSpaces(buffer: &buffer, tracker: tracker)
}
let (key, value) = try parseIDParamsList_element(buffer: &buffer, tracker: tracker)
var dic: OrderedDictionary<String, String?> = [key: value]
try PL.parseZeroOrMore(buffer: &buffer, into: &dic, tracker: tracker) { (buffer, tracker) -> (String, String?) in
try PL.parseSpaces(buffer: &buffer, tracker: tracker)
return try parseIDParamsList_element(buffer: &buffer, tracker: tracker)
}
_ = try PL.parseOptional(buffer: &buffer, tracker: tracker) { buffer, tracker in
try PL.parseSpaces(buffer: &buffer, tracker: tracker)
}
try PL.parseFixedString(")", buffer: &buffer, tracker: tracker)
return dic
}
Expand Down
21 changes: 21 additions & 0 deletions Tests/NIOIMAPCoreTests/Parser/IMAPParserTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1414,6 +1414,8 @@ extension ParserUnitTests {
testFunction: GrammarParser().parseIDParamsList,
validInputs: [
("NIL", " ", [:], #line),
("()", " ", [:], #line),
("( )", " ", [:], #line),
(#"("key1" "value1")"#, "", ["key1": "value1"], #line),
(
#"("key1" "value1" "key2" "value2" "key3" "value3")"#,
Expand All @@ -1427,6 +1429,25 @@ extension ParserUnitTests {
["key1": "£", "flag": "🏴󠁧󠁢󠁥󠁮󠁧󠁿"],
#line
),
(
#"("a" "1" "b" "2")"#,
"",
["a": "1", "b": "2"],
#line
),
// Extra spaces
(
#"( "a" "1" "b" "2" )"#,
"",
["a": "1", "b": "2"],
#line
),
(
#"("a" "1" "b" "2")"#,
"",
["a": "1", "b": "2"],
#line
),
],
parserErrorInputs: [],
incompleteMessageInputs: []
Expand Down

0 comments on commit 7328a73

Please sign in to comment.