Skip to content

Commit 7e776c8

Browse files
Fix LT-22125: Clear out DefaultCollations that don't Validate
After a thorough investigation of current LCM and palaso code I can't find any places where SystemCollationDefinitions were not Validated before being set in the DefaultCollation There was that possibility here, but I couldn't reliably reproduce the bug. This *may* address the root cause and it will prevent any repeated crashing due to this type of writing system data error
1 parent 4e115ca commit 7e776c8

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

Src/Common/FieldWorks/FieldWorks.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -872,16 +872,20 @@ private static void EnsureDefaultCollationsPresent(LcmCache cache)
872872
StringBuilder nullCollationWs = new StringBuilder();
873873
foreach (CoreWritingSystemDefinition ws in cache.ServiceLocator.WritingSystems.AllWritingSystems)
874874
{
875-
if (ws != null && ws.DefaultCollation == null)
875+
if (ws != null && (ws.DefaultCollation == null || !ws.DefaultCollation.Validate(out _)))
876876
{
877877
ws.DefaultCollation = new IcuRulesCollationDefinition("standard");
878878
nullCollationWs.Append(ws.DisplayLabel + ",");
879879
}
880880
// Check for invalid collation here rather than in RecordSorter to avoid LT-21461 problem.
881-
// This may also repair the previous if statement.
882881
if (ws != null && ws.DefaultCollation != null && InvalidCollation(ws.DefaultCollation))
883882
{
884-
ws.DefaultCollation = new SystemCollationDefinition { LanguageTag = ws.LanguageTag };
883+
CollationDefinition cd;
884+
if (SystemCollator.ValidateLanguageTag(ws.LanguageTag, out _))
885+
cd = new SystemCollationDefinition { LanguageTag = ws.LanguageTag };
886+
else
887+
cd = new IcuRulesCollationDefinition("standard");
888+
ws.DefaultCollation = cd;
885889
}
886890
}
887891
if (nullCollationWs.Length > 0)

0 commit comments

Comments
 (0)