[corlib] Fixes TimeZoneInfo.ParseTZBuffer abbrevs.
authorMarcos Henrich <marcos.henrich@xamarin.com>
Thu, 12 Nov 2015 19:00:43 +0000 (19:00 +0000)
committerMarcos Henrich <marcos.henrich@xamarin.com>
Fri, 13 Nov 2015 15:51:12 +0000 (15:51 +0000)
Context: https://bugzilla.xamarin.com/show_bug.cgi?id=31432

In a few android devices TimeZoneInfo.ParseTZBuffer was failing ito
parse Europe/Moscow with:
at System.ThrowHelper.ThrowKeyNotFoundException ()
at System.Collections.Generic.Dictionary`2[System.Int32,System.String].get_Item (Int32 key)mscorlib/system/collections/generic/dictionary.cs:176
at System.TimeZoneInfo.ParseTimesTypes (System.Byte[] buffer, Int32 index, Int32 count, System.Collections.Generic.Dictionary`2 abbreviations) [0x0002f] in mcs/class/corlib/System/TimeZoneInfo.cs:1293
at System.TimeZoneInfo.ParseTZBuffer (System.String id, System.Byte[] buffer, Int32 length)

It was failing while getting the third index [3] from] from abbrevs.

abbrevs added values were the following:
[0, MMT]
[1, MT]
[2, T]
[4, MST]
[5, ST]
[6, T]
[8, MDST]
[9, DST]
[10, ST]
[11, T]
[13, S]
[15, M]
[17, MSK]
[18, SK]
[19, K]
[21, EET]
[22, ET]
[23, T]
[25, MSD]
[26, SD]
[27, D]
[29, EEST]
[30, EST]
[31, ST]
[32, T]

Index 3 was not added because its values is an empty string, as indexes
with empty values are used in this case we are now adding them to the
abbrevs dictionary.

Fixes #31432

mcs/class/corlib/System/TimeZoneInfo.cs

index d3fc6ff2c6615a6614d78497aab908a3d13d5bd6..7cfd975f56316609074117ae8902d9ffcee813a5 100644 (file)
@@ -1378,7 +1378,8 @@ namespace System
                                else {
                                        abbrevs.Add (abbrev_index, sb.ToString ());
                                        //Adding all the substrings too, as it seems to be used, at least for Africa/Windhoek
-                                       for (int j = 1; j < sb.Length; j++)
+                                       //j == sb.Length empty substring also needs to be added #31432
+                                       for (int j = 1; j <= sb.Length; j++)
                                                abbrevs.Add (abbrev_index + j, sb.ToString (j, sb.Length - j));
                                        abbrev_index = i + 1;
                                        sb = new StringBuilder ();