Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in readQuotedString: recognize leading escaped character #10

Merged
merged 2 commits into from
Mar 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions lib/src/imap_buffer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,16 @@ class ImapBuffer {
List<int> charCodes = <int>[];
int nextChar = await _getCharCode(proceed: true);
while (nextChar != 34 /* " */) {
charCodes.add(nextChar);
nextChar = await _getCharCode(proceed: true);
if (nextChar == 92 /* \ */) {
nextChar = await _getCharCode(proceed: true); // skip first backslash
if (nextChar == 92 /* \ */ || nextChar == 34 /* " */) {
charCodes.add(nextChar);
nextChar = await _getCharCode(proceed: true); // skip first backslash
} else {
if (nextChar != 34 /* " */ && nextChar != 92 /* \ */) {
// bad format, only escaped backslash or quotation mark are supported
throw new SyntaxErrorException(
"Unknown escape sequence \\${String.fromCharCode(nextChar)}");
}
}
charCodes.add(nextChar);
nextChar = await _getCharCode(proceed: true);
}
if (autoReleaseBuffer) _releaseUsedBuffer();
return new ImapWord(ImapWordType.string, String.fromCharCodes(charCodes));
Expand Down
5 changes: 5 additions & 0 deletions test/imap_buffer_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ void main() {
_controller.add(list);
expect((await _buffer.readQuotedString()).value, r'A \ backslash \');
});
test('String may start with escaped character', () async {
var list = r'"\"A quoted text\""'.codeUnits;
_controller.add(list);
expect((await _buffer.readQuotedString()).value, '"A quoted text"');
});
test('Throws SyntaxErrorException if a characeter besides ", \\ is escaped',
() async {
var list = r'"A bad \format"'.codeUnits;
Expand Down