Skip to content

Commit 91c7339

Browse files
committed
Add culture validation to ensure consistent behavior across platforms
1 parent 68405be commit 91c7339

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

src/CountryData.Globalization/Services/CountryDataProvider.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,17 @@ public IEnumerable<CultureInfo> GetAllCulturesForCountry(string shortCode)
373373
try
374374
{
375375
var cultureName = $"{languageCode}-{shortCode}";
376-
return CultureInfo.GetCultureInfo(cultureName);
376+
var culture = CultureInfo.GetCultureInfo(cultureName);
377+
378+
// Validate that the culture actually exists in the system
379+
// This ensures consistent behavior across Windows/Linux
380+
var allCultures = CultureInfo.GetCultures(CultureTypes.AllCultures);
381+
if (!allCultures.Any(c => c.Name.Equals(cultureName, StringComparison.OrdinalIgnoreCase)))
382+
{
383+
return null;
384+
}
385+
386+
return culture;
377387
}
378388
catch
379389
{

0 commit comments

Comments
 (0)