From 734a8d7612237b4fab066957318345b5b7b157fe Mon Sep 17 00:00:00 2001 From: Krzysztof Wicher Date: Thu, 18 Jan 2018 16:58:15 -0800 Subject: [PATCH] Do not throw IndexOutOfBounds when AM/PM designator is empty (#15904) * do not throw IndexOutOfBounds when AM/PM designator is empty * store am/pm designator in local --- src/mscorlib/shared/System/Globalization/DateTimeParse.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/mscorlib/shared/System/Globalization/DateTimeParse.cs b/src/mscorlib/shared/System/Globalization/DateTimeParse.cs index cbf9094..40962f8 100644 --- a/src/mscorlib/shared/System/Globalization/DateTimeParse.cs +++ b/src/mscorlib/shared/System/Globalization/DateTimeParse.cs @@ -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; -- 2.7.4