Make ContentType(string) constructor throw FormatException instead of IndexOutOfRange...
authorAvani Gupta <avanigupta@users.noreply.github.com>
Tue, 29 Sep 2020 11:30:55 +0000 (04:30 -0700)
committerGitHub <noreply@github.com>
Tue, 29 Sep 2020 11:30:55 +0000 (13:30 +0200)
src/libraries/Common/src/System/Net/Mail/MailBnfHelper.cs
src/libraries/System.Net.Mail/tests/Functional/ContentTypeTest.cs

index 0b9292f..b465942 100644 (file)
@@ -267,7 +267,7 @@ namespace System.Net.Mime
                 }
             }
 
-            if (start == offset)
+            if (start == offset && offset < data.Length)
             {
                 throw new FormatException(SR.Format(SR.MailHeaderFieldInvalidCharacter, data[offset]));
             }
index 2eabf68..603b910 100644 (file)
@@ -53,7 +53,7 @@ namespace System.Net.Mime.Tests
         [InlineData(typeof(FormatException), "text/plain; charset=utf-8 ,")]
         [InlineData(typeof(FormatException), "text/plain; charset=utf-8,")]
         [InlineData(typeof(FormatException), "textplain")]
-        [InlineData(typeof(IndexOutOfRangeException), "text/")]
+        [InlineData(typeof(FormatException), "text/")]
         [InlineData(typeof(FormatException), ",, , ,,text/plain; charset=iso-8859-1; q=1.0,\r\n */xml; charset=utf-8; q=0.5,,,")]
         [InlineData(typeof(FormatException), "text/plain; charset=iso-8859-1; q=1.0, */xml; charset=utf-8; q=0.5")]
         [InlineData(typeof(FormatException), " , */xml; charset=utf-8; q=0.5 ")]