Do not throw IndexOutOfBounds when AM/PM designator is empty (#15904)
authorKrzysztof Wicher <mordotymoja@gmail.com>
Fri, 19 Jan 2018 00:58:15 +0000 (16:58 -0800)
committerGitHub <noreply@github.com>
Fri, 19 Jan 2018 00:58:15 +0000 (16:58 -0800)
* do not throw IndexOutOfBounds when AM/PM designator is empty

* store am/pm designator in local

src/mscorlib/shared/System/Globalization/DateTimeParse.cs

index cbf9094..40962f8 100644 (file)
@@ -3607,15 +3607,18 @@ new DS[] { DS.ERROR, DS.TX_NNN,  DS.TX_NNN,  DS.TX_NNN,  DS.ERROR,   DS.ERROR,
             // change the code below.
             if (str.GetNext())
             {
-                if (str.GetChar() == dtfi.AMDesignator[0])
+                string amDesignator = dtfi.AMDesignator;
+                if (amDesignator.Length > 0 && str.GetChar() == amDesignator[0])
                 {
                     result = TM.AM;
-                    return (true);
+                    return true;
                 }
-                if (str.GetChar() == dtfi.PMDesignator[0])
+
+                string pmDesignator = dtfi.PMDesignator;
+                if (pmDesignator.Length > 0 && str.GetChar() == pmDesignator[0])
                 {
                     result = TM.PM;
-                    return (true);
+                    return true;
                 }
             }
             return false;