-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🥅 Return UnparsedData for unhandled response-data
Previously, unhandled `response-data` would attempt to parse to the end of the string using `text`. This would fail if the string contained either literals or binary data. The new `unparsed_response` approach simply grabs all remaining bytes (except for the final CRLF). Rather than simply return string data, the response's data uses a new `UnparsedData` struct, to unambiguously signal that the result may change if a future release starts parsing the string. The same approach has been copied over to `numeric_response`, allowing unhandled numeric responses to be handled more robustly as well. `IgnoredResponse` was converted to a subclass of `UntaggedResponse`, and assigns any remaining unparsed text to an `UnparsedData` struct. Other than the subclass, it is now treated like any other unknown/unparsed response type. +NOOP+ still returns IgnoredResponse.
- Loading branch information
Showing
3 changed files
with
60 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 17 additions & 3 deletions
20
test/net/imap/fixtures/response_parser/quirky_behaviors.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,23 @@ | ||
--- | ||
:tests: | ||
test_invalid_noop_response_is_ignored: | ||
:comment: | | ||
This should probably use UntaggedResponse, perhaps with an | ||
UnparsedResponseData object for its #data. | ||
:response: "* NOOP\r\n" | ||
:expected: !ruby/struct:Net::IMAP::IgnoredResponse | ||
name: "NOOP" | ||
raw_data: "* NOOP\r\n" | ||
|
||
test_invalid_noop_response_with_unparseable_data: | ||
:response: "* NOOP froopy snood\r\n" | ||
:expected: !ruby/struct:Net::IMAP::IgnoredResponse | ||
name: "NOOP" | ||
data: !ruby/struct:Net::IMAP::UnparsedData | ||
unparsed_data: "froopy snood" | ||
raw_data: "* NOOP froopy snood\r\n" | ||
|
||
test_invalid_noop_response_with_numeric_prefix: | ||
:response: "* 99 NOOP\r\n" | ||
:expected: !ruby/struct:Net::IMAP::IgnoredResponse | ||
name: "NOOP" | ||
data: !ruby/struct:Net::IMAP::UnparsedData | ||
number: 99 | ||
raw_data: "* 99 NOOP\r\n" |