Skip to content

Commit

Permalink
Modified TryParseMsgId to gobble ctrl chars in the local-part
Browse files Browse the repository at this point in the history
  • Loading branch information
jstedfast committed Sep 15, 2019
1 parent 446bd73 commit 7da9b81
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion MimeKit/Utils/ParseUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ public static bool TryParseMsgId (byte[] text, ref int index, int endIndex, bool
if (!SkipQuoted (text, ref index, endIndex, throwOnError))
return false;
} else {
while (index < endIndex && text[index] != (byte) '.' && text[index] != (byte) '@' && text[index] != '>' && !text[index].IsType (SpaceOrControl))
while (index < endIndex && text[index] != (byte) '.' && text[index] != (byte) '@' && text[index] != '>' && !text[index].IsBlank ())
index++;
}

Expand Down
38 changes: 19 additions & 19 deletions UnitTests/Utils/ParseUtilsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,24 +215,24 @@ public void TestTryParseMsgIdLessThanLocalPart ()
}
}

[Test]
public void TestTryParseMsgIdLessThanLocalPartCtrl ()
{
var buffer = Encoding.ASCII.GetBytes (" <local-part\b");
int index = 0;
string msgid;

Assert.IsFalse (ParseUtils.TryParseMsgId (buffer, ref index, buffer.Length, false, false, out msgid), "TryParseMsgId");

try {
index = 0;
ParseUtils.TryParseMsgId (buffer, ref index, buffer.Length, false, true, out msgid);
Assert.Fail ("throwOnError");
} catch (ParseException ex) {
Assert.AreEqual (1, ex.TokenIndex, "TokenIndex");
Assert.AreEqual (12, ex.ErrorIndex, "ErrorIndex");
}
}
//[Test]
//public void TestTryParseMsgIdLessThanLocalPartCtrl ()
//{
// var buffer = Encoding.ASCII.GetBytes (" <local-part\b");
// int index = 0;
// string msgid;

// Assert.IsFalse (ParseUtils.TryParseMsgId (buffer, ref index, buffer.Length, false, false, out msgid), "TryParseMsgId");

// try {
// index = 0;
// ParseUtils.TryParseMsgId (buffer, ref index, buffer.Length, false, true, out msgid);
// Assert.Fail ("throwOnError");
// } catch (ParseException ex) {
// Assert.AreEqual (1, ex.TokenIndex, "TokenIndex");
// Assert.AreEqual (12, ex.ErrorIndex, "ErrorIndex");
// }
//}

[Test]
public void TestTryParseMsgIdLessThanLocalPartDot ()
Expand Down Expand Up @@ -335,7 +335,7 @@ public void TestTryParseMsgIdInvalidInternationalLocalPart ()
ParseUtils.TryParseMsgId (buffer, ref index, buffer.Length, false, true, out msgid);
Assert.Fail ("throwOnError");
} catch (ParseException ex) {
Assert.AreEqual (1, ex.TokenIndex, "TokenIndex");
Assert.AreEqual (2, ex.TokenIndex, "TokenIndex");
Assert.AreEqual (2, ex.ErrorIndex, "ErrorIndex");
}
}
Expand Down

0 comments on commit 7da9b81

Please sign in to comment.