Skip to content

Commit 4bce02c

Browse files
Code Quality: Handle malformed localized format strings in search header (#17735)
Co-authored-by: seer-by-sentry[bot] <157164994+seer-by-sentry[bot]@users.noreply.github.com>
1 parent 848e2b2 commit 4bce02c

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

src/Files.App/ViewModels/ShellViewModel.cs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2736,9 +2736,25 @@ public async Task SearchAsync(FolderSearch search)
27362736
await ApplyFilesAndFoldersChangesAsync();
27372737
EmptyTextType = EmptyTextType.None;
27382738

2739-
SearchHeaderTitle = !string.IsNullOrEmpty(search.Query)
2740-
? string.Format(Strings.SearchResultsFor.GetLocalizedResource(), search.Query)
2741-
: string.Empty;
2739+
if (!string.IsNullOrEmpty(search.Query))
2740+
{
2741+
try
2742+
{
2743+
// Try to format the localized string with the search query
2744+
SearchHeaderTitle = string.Format(Strings.SearchResultsFor.GetLocalizedResource(), search.Query);
2745+
}
2746+
catch (FormatException ex)
2747+
{
2748+
// Handle malformed localized format strings (e.g., incorrect placeholders in translation)
2749+
// Fallback to a safe default format
2750+
App.Logger.LogWarning(ex, "Malformed localized format string for SearchResultsFor. Using fallback format.");
2751+
SearchHeaderTitle = $"Search results for \"{search.Query}\"";
2752+
}
2753+
}
2754+
else
2755+
{
2756+
SearchHeaderTitle = string.Empty;
2757+
}
27422758

27432759
if (SearchIconBitmapImage is null)
27442760
SearchIconBitmapImage ??= await UIHelpers.GetSearchIconResource();

0 commit comments

Comments
 (0)