Skip to content

test: Verify DateTimeFormatter tolerates unsupported preferred-language codes#23026

Open
MartinZikmund wants to merge 1 commit intomasterfrom
dev/mazi/repro/12423
Open

test: Verify DateTimeFormatter tolerates unsupported preferred-language codes#23026
MartinZikmund wants to merge 1 commit intomasterfrom
dev/mazi/repro/12423

Conversation

@MartinZikmund
Copy link
Copy Markdown
Member

Closes #12423

Summary

Issue #12423 reports that CalendarDatePicker crashes on iOS when the device's Preferred Languages list combines a language with a region whose product isn't a real culture (e.g. preferred "Italian" + region "United States" surfaced as it-US). The reported stack goes through DateTimeFormatter's internal new CultureInfo(Languages[0]) which threw CultureNotFoundException.

This test exercises the cross-platform language-list constructor with "it-US" in the list and asserts that the formatter constructs and produces a non-empty formatted string.

The test passes on current master (Skia Desktop target).

Test(s) added

  • src/Uno.UI.RuntimeTests/Tests/Windows_Globalization/Given_DateTimeFormatter.csGiven_DateTimeFormatter.When_Languages_Contains_Unsupported_Culture_Should_Not_Throw_12423

Notes

The issue was reported on iOS (Xamarin.iOS, Uno 4.8.39). The crash path depends on the iOS mono runtime's stricter CultureInfo handling. Validation on native iOS with the exact language configuration is still recommended.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new Uno runtime test intended to prevent regressions where DateTimeFormatter fails/crashes when its language list contains a preferred-language tag that may not map to a supported CultureInfo (as reported in issue #12423 impacting CalendarDatePicker on iOS).

Changes:

  • Add a regression test that constructs a DateTimeFormatter with a language list containing "it-US" and asserts formatting returns a non-empty string.
  • Add inline comments documenting the iOS reproduction scenario and expected behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +140 to +154
// Reproduction for https://github.com/unoplatform/uno/issues/12423
// On iOS, when the device's preferred languages list combines a language
// with a region that isn't a real culture (e.g. preferred language "it"
// with region "US" can surface as "it-US"), CalendarDatePicker fails to
// construct because DateTimeFormatter eagerly calls `new CultureInfo(...)`
// on each language string and throws CultureNotFoundException. This is
// exercised cross-platform via the (language-list) constructor overload.
[TestMethod]
public void When_Languages_Contains_Unsupported_Culture_Should_Not_Throw_12423()
{
var formatter = new DateTimeFormatter("longdate", new[] { "it-US", "en-US" });

Assert.IsNotNull(formatter);
var formatted = formatter.Format(new DateTimeOffset(2024, 1, 15, 0, 0, 0, TimeSpan.Zero));
Assert.IsFalse(string.IsNullOrEmpty(formatted), "Formatter should produce a non-empty string even when the preferred language is unsupported.");
@unodevops
Copy link
Copy Markdown
Contributor

🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-23026/wasm-skia-net9/index.html

@unodevops
Copy link
Copy Markdown
Contributor

⚠️⚠️ The build 206860 has failed on Uno.UI - CI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[iOS] CalendarDatePicker doesn't work when in the settings more than one preferred language is added

3 participants