Skip to content

Commit 08d5cf7

Browse files
committed
Simplified illegal ctrl char ccheck logic for quoted-strings in addr-specs
Also added definition obs-qp for reference and explained why we are not going to support escaped ctrl characters even though, technically, obs-qp allows them (the newer syntax does not).
1 parent 5c79dcc commit 08d5cf7

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

MimeKit/InternetAddress.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,14 @@ static bool SkipQuoted (byte[] text, ref int index, int endIndex, bool throwOnEr
327327
// VCHAR = %x21-7E ; visible (printing) characters
328328
//
329329
// WSP = SP / HTAB ; white space
330+
//
331+
// obs-qp = "\" (%d0 / obs-NO-WS-CTL / LF / CR)
332+
//
333+
// obs-NO-WS-CTL = %d1-8 / ; US-ASCII control
334+
// %d11 / ; characters that do not
335+
// %d12 / ; include the carriage
336+
// %d14-31 / ; return, line feed, and
337+
// %d127 ; white space characters
330338
int startIndex = index;
331339
bool escaped = false;
332340

@@ -348,14 +356,16 @@ static bool SkipQuoted (byte[] text, ref int index, int endIndex, bool throwOnEr
348356
// to that, obs-qtext also explicitly allows linear whitespace (SPACE %d32 and HTAB %d09), so
349357
// the only characters that are not allowed are the control characters (%d0-8 and %d10-31),
350358
// the double-quote character (%d34), and the delete character (%d127).
351-
if (c < 9 || (c > 9 && c < 32) || c == 34 || c == 127) {
359+
if ((c < 32 && c != 9) || c == 127) {
352360
if (throwOnError)
353361
throw new ParseException (string.Format (CultureInfo.InvariantCulture, "Invalid character in quoted-string token at offset {0}", startIndex), startIndex, index);
354362

355363
return false;
356364
}
357365
} else {
358-
if (c < 9 || (c > 9 && c < 32) || c == 127) {
366+
// Note: We are going to make the decision to not support any escaped ctrl characters even
367+
// though they are allowed by obs-qp. They are just too dangerous.
368+
if ((c < 32 && c != 9) || c == 127) {
359369
if (throwOnError)
360370
throw new ParseException (string.Format (CultureInfo.InvariantCulture, "Invalid quoted-pair in quoted-string token at offset {0}", startIndex), startIndex, index);
361371

0 commit comments

Comments
 (0)