Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- [L10NSharp] Removed emailForSubmissions parameter from LocalizationManager.Create. Since the localization dialog was jettisoned, it no longer makes sense to store this information on the localization manager.
- [L10NSharp.Windows.Forms] Removed emailForSubmissions parameter (8th parameter) from LocalizationManagerWinforms.Create. Since the localization dialog was jettisoned, it no longer makes sense to store this information on the localization manager.
- [L10NSharp] Replaced the .NET 8.0 target with .NET Standard 2.0 for broader compatibility.
- [L10NSharp] BREAKING CHANGE: `LocalizationManager.GetString`, `GetDynamicString`, and `GetDynamicStringOrEnglish` now throw `ArgumentException` when called with a null or empty string ID. Previously, empty IDs were silently accepted and could produce a malformed XLIFF file that crashed on next launch. (#104)

### Fixed

Expand Down
14 changes: 14 additions & 0 deletions src/L10NSharp.Tests/LocalizationManagerTestsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,20 @@ public void GetDynamicStringInEnglish_NoDefault_FindsEnglish()
}
}

[Test]
public void GetDynamicString_WithEmptyId_ThrowsArgumentException()
{
Assert.Throws<ArgumentException>(() =>
LocalizationManager.GetDynamicString(AppId, "", "some text"));
}

[Test]
public void GetDynamicStringOrEnglish_WithEmptyId_ThrowsArgumentException()
{
Assert.Throws<ArgumentException>(() =>
LocalizationManagerInternal<T>.GetDynamicStringOrEnglish(AppId, "", "some text", null, "en"));
}

[Test]
public void GetDynamicStringOrEnglish_LmDisposed_GivesUsefulException()
{
Expand Down
4 changes: 4 additions & 0 deletions src/L10NSharp/LocalizationManagerInternal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,8 @@ public static string GetDynamicString(string appId, string id, string englishTex
/// ------------------------------------------------------------------------------------
public static string GetDynamicString(string appId, string id, string englishText, string comment)
{
if (string.IsNullOrWhiteSpace(id))
throw new ArgumentException("id may not be null or empty.", nameof(id));
return GetDynamicStringOrEnglish(appId, id, englishText, comment, LocalizationManager.UILanguageId);
}

Expand All @@ -482,6 +484,8 @@ public static string GetDynamicString(string appId, string id, string englishTex
public static string GetDynamicStringOrEnglish(string appId, string id, string englishText,
string comment, string langId)
{
if (string.IsNullOrWhiteSpace(id))
throw new ArgumentException("id may not be null or empty.", nameof(id));
// This happens in unit test environments or apps that have imported a library that
// is localized, but the app itself isn't initializing L10N yet.
if (LoadedManagers.Count == 0)
Expand Down
2 changes: 2 additions & 0 deletions src/L10NSharp/XLiffUtils/XliffTransUnitUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ internal bool Update(LocalizingInfo locInfo)
// Can't do anything without a language id.
if (string.IsNullOrEmpty(locInfo.LangId))
return _updated;
if (string.IsNullOrEmpty(locInfo.Id))
return _updated;

var xliffSource = _stringCache.GetDocument(_defaultLang);
Debug.Assert(xliffSource != null);
Expand Down
Loading