test: Verify DateTimeFormatter tolerates unsupported preferred-language codes#23026
Open
MartinZikmund wants to merge 1 commit intomasterfrom
Open
test: Verify DateTimeFormatter tolerates unsupported preferred-language codes#23026MartinZikmund wants to merge 1 commit intomasterfrom
MartinZikmund wants to merge 1 commit intomasterfrom
Conversation
… codes Relates to #12423
Contributor
There was a problem hiding this comment.
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
DateTimeFormatterwith 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."); |
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 |
Contributor
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #12423
Summary
Issue #12423 reports that
CalendarDatePickercrashes 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 asit-US). The reported stack goes throughDateTimeFormatter's internalnew CultureInfo(Languages[0])which threwCultureNotFoundException.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.cs→Given_DateTimeFormatter.When_Languages_Contains_Unsupported_Culture_Should_Not_Throw_12423Notes
The issue was reported on iOS (Xamarin.iOS, Uno 4.8.39). The crash path depends on the iOS mono runtime's stricter
CultureInfohandling. Validation on native iOS with the exact language configuration is still recommended.