From c5e9567875e12204df3f4775007888dbedb686f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Tue, 2 May 2023 21:22:52 +0200 Subject: [PATCH] Fix a null reference exception upon empty Fluent strings. --- OpenRA.Mods.Common/Lint/CheckTranslationReference.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/OpenRA.Mods.Common/Lint/CheckTranslationReference.cs b/OpenRA.Mods.Common/Lint/CheckTranslationReference.cs index e01c7948e4..7857fda0af 100644 --- a/OpenRA.Mods.Common/Lint/CheckTranslationReference.cs +++ b/OpenRA.Mods.Common/Lint/CheckTranslationReference.cs @@ -28,7 +28,7 @@ namespace OpenRA.Mods.Common.Lint readonly Dictionary referencedVariablesPerKey = new(); readonly List variableReferences = new(); - void TestTraits(Ruleset rules, Action testKey) + void TestTraits(Ruleset rules, Action emitError, Action testKey) { foreach (var actorInfo in rules.Actors) { @@ -44,6 +44,12 @@ namespace OpenRA.Mods.Common.Lint var keys = LintExts.GetFieldValues(traitInfo, field, translationReference.DictionaryReference); foreach (var key in keys) { + if (key == null) + { + emitError($"Trait `{traitInfo.InstanceName}` on field `{field.Name}` has an empty translation reference."); + continue; + } + if (referencedKeys.Contains(key)) continue; @@ -65,7 +71,7 @@ namespace OpenRA.Mods.Common.Lint var modTranslation = new Translation(language, modData.Manifest.Translations, modData.DefaultFileSystem, _ => { }); var mapTranslation = new Translation(language, FieldLoader.GetValue("value", map.TranslationDefinitions.Value), map, error => emitError(error.ToString())); - TestTraits(map.Rules, key => + TestTraits(map.Rules, emitError, key => { if (modTranslation.HasMessage(key)) { @@ -84,7 +90,7 @@ namespace OpenRA.Mods.Common.Lint Console.WriteLine($"Testing translation: {language}"); var translation = new Translation(language, modData.Manifest.Translations, modData.DefaultFileSystem, error => emitError(error.ToString())); - TestTraits(modData.DefaultRules, key => + TestTraits(modData.DefaultRules, emitError, key => { if (!translation.HasMessage(key)) emitError($"{key} not present in `{language}` translation.");