From cff1dd20507d39760eda60d99cccbc2ea3780e61 Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Mon, 10 Jun 2024 15:28:38 +0200 Subject: [PATCH 1/4] convert narrow no-break spaces to spaces too --- .../System/Globalization/CultureData.Icu.cs | 44 +++++++++--- .../System/Globalization/CultureData.Unix.cs | 4 -- .../src/System/Globalization/CultureData.cs | 4 -- .../System/Globalization/CultureData.iOS.cs | 68 ------------------- .../DateTimeFormatInfoLongTimePattern.cs | 8 +++ .../DateTimeFormatInfoShortTimePattern.cs | 8 +++ .../runtime/hybrid-globalization/helpers.ts | 6 +- 7 files changed, 52 insertions(+), 90 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Icu.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Icu.cs index c6061ed1bd852..513b5ace46141 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Icu.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Icu.cs @@ -291,18 +291,29 @@ private unsafe string IcuGetTimeFormatString(bool shortFormat) Debug.Assert(!GlobalizationMode.UseNls); Debug.Assert(_sWindowsName != null, "[CultureData.GetTimeFormatString(bool shortFormat)] Expected _sWindowsName to be populated already"); - char* buffer = stackalloc char[ICU_ULOC_KEYWORD_AND_VALUES_CAPACITY]; - - bool result = Interop.Globalization.GetLocaleTimeFormat(_sWindowsName, shortFormat, buffer, ICU_ULOC_KEYWORD_AND_VALUES_CAPACITY); - if (!result) + ReadOnlySpan span; +#if TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS + if (GlobalizationMode.Hybrid) { - // Failed, just use empty string - Debug.Fail("[CultureData.GetTimeFormatString(bool shortFormat)] Failed"); - return string.Empty; + string res = Interop.Globalization.GetLocaleTimeFormatNative(_sWindowsName, shortFormat); + span = res != null ? new ReadOnlySpan(ref res.GetRawStringData(), res.Length) : ReadOnlySpan.Empty; + } + else +#endif + { + char* buffer = stackalloc char[ICU_ULOC_KEYWORD_AND_VALUES_CAPACITY]; + bool result = Interop.Globalization.GetLocaleTimeFormat(_sWindowsName, shortFormat, buffer, ICU_ULOC_KEYWORD_AND_VALUES_CAPACITY); + if (!result) + { + // Failed, just use empty string + Debug.Fail("[CultureData.GetTimeFormatString(bool shortFormat)] Failed"); + return string.Empty; + } + span = new ReadOnlySpan(buffer, ICU_ULOC_KEYWORD_AND_VALUES_CAPACITY); + span = span.Slice(0, span.IndexOf('\0')); } - var span = new ReadOnlySpan(buffer, ICU_ULOC_KEYWORD_AND_VALUES_CAPACITY); - return ConvertIcuTimeFormatString(span.Slice(0, span.IndexOf('\0'))); + return ConvertIcuTimeFormatString(span); } // no support to lookup by region name, other than the hard-coded list in CultureData @@ -368,12 +379,23 @@ private static string ConvertIcuTimeFormatString(ReadOnlySpan icuFormatStr case 'h': case 'm': case 's': + result[resultPos++] = current; + break; case ' ': case '\u00A0': // no-break space case '\u202F': // narrow no-break space - result[resultPos++] = current; +#if TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS + if (GlobalizationMode.Hybrid) + { + // Convert nonbreaking and narrow no-break spaces into regular spaces + result[resultPos++] = ' '; + } + else +#endif + { + result[resultPos++] = current; + } break; - case 'a': // AM/PM if (!amPmAdded) { diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Unix.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Unix.cs index 6291881ba96e0..2a253d5367be3 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Unix.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Unix.cs @@ -20,11 +20,7 @@ internal sealed partial class CultureData private string[]? GetTimeFormatsCore(bool shortFormat) { -#if TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS - string format = GlobalizationMode.Hybrid ? GetTimeFormatStringNative(shortFormat) : IcuGetTimeFormatString(shortFormat); -#else string format = IcuGetTimeFormatString(shortFormat); -#endif return new string[] { format }; } diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs index aff4cd0e13f26..ed28dd5147a92 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs @@ -1978,11 +1978,7 @@ internal string TimeSeparator } else { -#if TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS - string? longTimeFormat = GlobalizationMode.Hybrid ? GetTimeFormatStringNative() : IcuGetTimeFormatString(); -#else string? longTimeFormat = ShouldUseUserOverrideNlsData ? NlsGetTimeFormatString() : IcuGetTimeFormatString(); -#endif if (string.IsNullOrEmpty(longTimeFormat)) { longTimeFormat = LongTimes[0]; diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.iOS.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.iOS.cs index 0617855576a88..85be8ee54bcdd 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.iOS.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.iOS.cs @@ -7,8 +7,6 @@ namespace System.Globalization { internal sealed partial class CultureData { - private const int LOC_FULLNAME_CAPACITY = 157; // max size of locale name - internal static string GetLocaleNameNative(string localeName) { return Interop.Globalization.GetLocaleNameNative(localeName); @@ -64,71 +62,5 @@ private int[] GetLocaleInfoNative(LocaleGroupingData type) return new int[] { primaryGroupingSize, secondaryGroupingSize }; } - - private string GetTimeFormatStringNative() => GetTimeFormatStringNative(shortFormat: false); - - private string GetTimeFormatStringNative(bool shortFormat) - { - Debug.Assert(_sWindowsName != null, "[CultureData.GetTimeFormatStringNative(bool shortFormat)] Expected _sWindowsName to be populated already"); - - string result = Interop.Globalization.GetLocaleTimeFormatNative(_sWindowsName, shortFormat); - - return ConvertNativeTimeFormatString(result); - } - - private static string ConvertNativeTimeFormatString(string nativeFormatString) - { - Span result = stackalloc char[LOC_FULLNAME_CAPACITY]; - - bool amPmAdded = false; - int resultPos = 0; - - for (int i = 0; i < nativeFormatString.Length; i++) - { - switch (nativeFormatString[i]) - { - case '\'': - result[resultPos++] = nativeFormatString[i++]; - while (i < nativeFormatString.Length) - { - char current = nativeFormatString[i]; - result[resultPos++] = current; - if (current == '\'') - { - break; - } - i++; - } - break; - - case ':': - case '.': - case 'H': - case 'h': - case 'm': - case 's': - result[resultPos++] = nativeFormatString[i]; - break; - - case ' ': - case '\u00A0': - // Convert nonbreaking spaces into regular spaces - result[resultPos++] = ' '; - break; - - case 'a': // AM/PM - if (!amPmAdded) - { - amPmAdded = true; - result[resultPos++] = 't'; - result[resultPos++] = 't'; - } - break; - - } - } - - return result.Slice(0, resultPos).ToString(); - } } } diff --git a/src/libraries/System.Runtime/tests/System.Globalization.Tests/DateTimeFormatInfo/DateTimeFormatInfoLongTimePattern.cs b/src/libraries/System.Runtime/tests/System.Globalization.Tests/DateTimeFormatInfo/DateTimeFormatInfoLongTimePattern.cs index 122eff9b4a77e..e176335240f66 100644 --- a/src/libraries/System.Runtime/tests/System.Globalization.Tests/DateTimeFormatInfo/DateTimeFormatInfoLongTimePattern.cs +++ b/src/libraries/System.Runtime/tests/System.Globalization.Tests/DateTimeFormatInfo/DateTimeFormatInfoLongTimePattern.cs @@ -283,5 +283,13 @@ public void LongTimePattern_CheckReadingTimeFormatWithSingleQuotes_ICU() } } } + + [Fact] + public void LongTimePattern_CheckTimeFormatWithSpaces() + { + var date = DateTime.Today + TimeSpan.FromHours(15) + TimeSpan.FromMinutes(15); + var culture = new CultureInfo("en-US"); + Assert.Equal("3:15:00 PM", date.ToString("T", culture)); + } } } diff --git a/src/libraries/System.Runtime/tests/System.Globalization.Tests/DateTimeFormatInfo/DateTimeFormatInfoShortTimePattern.cs b/src/libraries/System.Runtime/tests/System.Globalization.Tests/DateTimeFormatInfo/DateTimeFormatInfoShortTimePattern.cs index e9a891fb7ade7..843964afddfab 100644 --- a/src/libraries/System.Runtime/tests/System.Globalization.Tests/DateTimeFormatInfo/DateTimeFormatInfoShortTimePattern.cs +++ b/src/libraries/System.Runtime/tests/System.Globalization.Tests/DateTimeFormatInfo/DateTimeFormatInfoShortTimePattern.cs @@ -254,5 +254,13 @@ public void ShortTimePattern_SetReadOnly_ThrowsInvalidOperationException() { Assert.Throws(() => DateTimeFormatInfo.InvariantInfo.ShortTimePattern = "HH:mm"); } + + [Fact] + public void ShortTimePattern_CheckTimeFormatWithSpaces() + { + var date = DateTime.Today + TimeSpan.FromHours(15) + TimeSpan.FromMinutes(15); + var culture = new CultureInfo("en-US"); + Assert.Equal("3:15 PM", date.ToString("t", culture)); + } } } diff --git a/src/mono/browser/runtime/hybrid-globalization/helpers.ts b/src/mono/browser/runtime/hybrid-globalization/helpers.ts index 0cd2294447226..52e1943b0c58b 100644 --- a/src/mono/browser/runtime/hybrid-globalization/helpers.ts +++ b/src/mono/browser/runtime/hybrid-globalization/helpers.ts @@ -27,11 +27,11 @@ export function normalizeLocale (locale: string | null) { } export function normalizeSpaces (pattern: string) { - if (!pattern.includes("\u202F")) + if (!pattern.includes("\u202F") && !pattern.includes("\u00A0")) return pattern; - // if U+202F present, replace them with spaces - return pattern.replace("\u202F", "\u0020"); + // Replace both \u202F and \u00A0 with a regular space \u0020 + return pattern.replace(/[\u202F\u00A0]/g, "\u0020"); } From 49335c2ebc28bcec45f6d4da4b5ec6e104568f4f Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Mon, 10 Jun 2024 16:55:34 +0200 Subject: [PATCH 2/4] Enable test cases only for ICU and hybrid mode --- .../DateTimeFormatInfo/DateTimeFormatInfoLongTimePattern.cs | 2 +- .../DateTimeFormatInfo/DateTimeFormatInfoShortTimePattern.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Runtime/tests/System.Globalization.Tests/DateTimeFormatInfo/DateTimeFormatInfoLongTimePattern.cs b/src/libraries/System.Runtime/tests/System.Globalization.Tests/DateTimeFormatInfo/DateTimeFormatInfoLongTimePattern.cs index e176335240f66..6e6434c3af6b9 100644 --- a/src/libraries/System.Runtime/tests/System.Globalization.Tests/DateTimeFormatInfo/DateTimeFormatInfoLongTimePattern.cs +++ b/src/libraries/System.Runtime/tests/System.Globalization.Tests/DateTimeFormatInfo/DateTimeFormatInfoLongTimePattern.cs @@ -284,7 +284,7 @@ public void LongTimePattern_CheckReadingTimeFormatWithSingleQuotes_ICU() } } - [Fact] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsIcuGlobalization), nameof(PlatformDetection.IsHybridGlobalizationOnBrowser))] public void LongTimePattern_CheckTimeFormatWithSpaces() { var date = DateTime.Today + TimeSpan.FromHours(15) + TimeSpan.FromMinutes(15); diff --git a/src/libraries/System.Runtime/tests/System.Globalization.Tests/DateTimeFormatInfo/DateTimeFormatInfoShortTimePattern.cs b/src/libraries/System.Runtime/tests/System.Globalization.Tests/DateTimeFormatInfo/DateTimeFormatInfoShortTimePattern.cs index 843964afddfab..0df9421aa19f2 100644 --- a/src/libraries/System.Runtime/tests/System.Globalization.Tests/DateTimeFormatInfo/DateTimeFormatInfoShortTimePattern.cs +++ b/src/libraries/System.Runtime/tests/System.Globalization.Tests/DateTimeFormatInfo/DateTimeFormatInfoShortTimePattern.cs @@ -255,7 +255,7 @@ public void ShortTimePattern_SetReadOnly_ThrowsInvalidOperationException() Assert.Throws(() => DateTimeFormatInfo.InvariantInfo.ShortTimePattern = "HH:mm"); } - [Fact] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsIcuGlobalization), nameof(PlatformDetection.IsHybridGlobalizationOnBrowser))] public void ShortTimePattern_CheckTimeFormatWithSpaces() { var date = DateTime.Today + TimeSpan.FromHours(15) + TimeSpan.FromMinutes(15); From f107812b74a3a4af4243c4b0ffabc3db889ebeb9 Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Tue, 11 Jun 2024 10:53:13 +0200 Subject: [PATCH 3/4] Pass non-breaking, narrow non-breaking space as they are --- .../src/System/Globalization/CultureData.Icu.cs | 14 +------------- .../DateTimeFormatInfoLongTimePattern.cs | 10 ++++++++-- .../DateTimeFormatInfoShortTimePattern.cs | 10 ++++++++-- .../runtime/hybrid-globalization/calendar.ts | 6 ++---- .../runtime/hybrid-globalization/culture-info.ts | 4 ++-- .../runtime/hybrid-globalization/helpers.ts | 9 --------- 6 files changed, 21 insertions(+), 32 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Icu.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Icu.cs index 513b5ace46141..703ced9d15f5c 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Icu.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Icu.cs @@ -379,22 +379,10 @@ private static string ConvertIcuTimeFormatString(ReadOnlySpan icuFormatStr case 'h': case 'm': case 's': - result[resultPos++] = current; - break; case ' ': case '\u00A0': // no-break space case '\u202F': // narrow no-break space -#if TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS - if (GlobalizationMode.Hybrid) - { - // Convert nonbreaking and narrow no-break spaces into regular spaces - result[resultPos++] = ' '; - } - else -#endif - { - result[resultPos++] = current; - } + result[resultPos++] = current; break; case 'a': // AM/PM if (!amPmAdded) diff --git a/src/libraries/System.Runtime/tests/System.Globalization.Tests/DateTimeFormatInfo/DateTimeFormatInfoLongTimePattern.cs b/src/libraries/System.Runtime/tests/System.Globalization.Tests/DateTimeFormatInfo/DateTimeFormatInfoLongTimePattern.cs index 6e6434c3af6b9..7a410d9dad5e5 100644 --- a/src/libraries/System.Runtime/tests/System.Globalization.Tests/DateTimeFormatInfo/DateTimeFormatInfoLongTimePattern.cs +++ b/src/libraries/System.Runtime/tests/System.Globalization.Tests/DateTimeFormatInfo/DateTimeFormatInfoLongTimePattern.cs @@ -284,12 +284,18 @@ public void LongTimePattern_CheckReadingTimeFormatWithSingleQuotes_ICU() } } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsIcuGlobalization), nameof(PlatformDetection.IsHybridGlobalizationOnBrowser))] + [Fact] public void LongTimePattern_CheckTimeFormatWithSpaces() { var date = DateTime.Today + TimeSpan.FromHours(15) + TimeSpan.FromMinutes(15); var culture = new CultureInfo("en-US"); - Assert.Equal("3:15:00 PM", date.ToString("T", culture)); + string formattedDate = date.ToString("t", culture); + bool containsSpace = formattedDate.Contains(' '); + bool containsNoBreakSpace = formattedDate.Contains('\u00A0'); + bool containsNarrowNoBreakSpace = formattedDate.Contains('\u202F'); + + Assert.True(containsSpace || containsNoBreakSpace || containsNarrowNoBreakSpace, + $"Formatted date string '{formattedDate}' does not contain any of the specified spaces."); } } } diff --git a/src/libraries/System.Runtime/tests/System.Globalization.Tests/DateTimeFormatInfo/DateTimeFormatInfoShortTimePattern.cs b/src/libraries/System.Runtime/tests/System.Globalization.Tests/DateTimeFormatInfo/DateTimeFormatInfoShortTimePattern.cs index 0df9421aa19f2..2e905a88634be 100644 --- a/src/libraries/System.Runtime/tests/System.Globalization.Tests/DateTimeFormatInfo/DateTimeFormatInfoShortTimePattern.cs +++ b/src/libraries/System.Runtime/tests/System.Globalization.Tests/DateTimeFormatInfo/DateTimeFormatInfoShortTimePattern.cs @@ -255,12 +255,18 @@ public void ShortTimePattern_SetReadOnly_ThrowsInvalidOperationException() Assert.Throws(() => DateTimeFormatInfo.InvariantInfo.ShortTimePattern = "HH:mm"); } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsIcuGlobalization), nameof(PlatformDetection.IsHybridGlobalizationOnBrowser))] + [Fact] public void ShortTimePattern_CheckTimeFormatWithSpaces() { var date = DateTime.Today + TimeSpan.FromHours(15) + TimeSpan.FromMinutes(15); var culture = new CultureInfo("en-US"); - Assert.Equal("3:15 PM", date.ToString("t", culture)); + string formattedDate = date.ToString("t", culture); + bool containsSpace = formattedDate.Contains(' '); + bool containsNoBreakSpace = formattedDate.Contains('\u00A0'); + bool containsNarrowNoBreakSpace = formattedDate.Contains('\u202F'); + + Assert.True(containsSpace || containsNoBreakSpace || containsNarrowNoBreakSpace, + $"Formatted date string '{formattedDate}' does not contain any of the specified spaces."); } } } diff --git a/src/mono/browser/runtime/hybrid-globalization/calendar.ts b/src/mono/browser/runtime/hybrid-globalization/calendar.ts index dccb97820f1ff..2a0d3ce70cbc6 100644 --- a/src/mono/browser/runtime/hybrid-globalization/calendar.ts +++ b/src/mono/browser/runtime/hybrid-globalization/calendar.ts @@ -5,7 +5,7 @@ import { VoidPtrNull } from "../types/internal"; import { runtimeHelpers } from "./module-exports"; import { Int32Ptr, VoidPtr } from "../types/emscripten"; -import { INNER_SEPARATOR, OUTER_SEPARATOR, normalizeSpaces } from "./helpers"; +import { INNER_SEPARATOR, OUTER_SEPARATOR } from "./helpers"; const MONTH_CODE = "MMMM"; const YEAR_CODE = "yyyy"; @@ -96,7 +96,6 @@ function getMonthYearPattern (locale: string | undefined, date: Date): string { pattern = pattern.replace("999", YEAR_CODE); // sometimes the number is localized and the above does not have an effect const yearStr = date.toLocaleDateString(locale, { year: "numeric" }); - pattern = normalizeSpaces(pattern); return pattern.replace(yearStr, YEAR_CODE); } @@ -165,7 +164,7 @@ function getShortDatePattern (locale: string | undefined): string { const localizedDayCode = dayStr.length == 1 ? "d" : "dd"; pattern = pattern.replace(dayStr, localizedDayCode); } - return normalizeSpaces(pattern); + return pattern; } function getLongDatePattern (locale: string | undefined, date: Date): string { @@ -196,7 +195,6 @@ function getLongDatePattern (locale: string | undefined, date: Date): string { pattern = pattern.replace(replacedWeekday, "dddd"); pattern = pattern.replace("22", DAY_CODE); const dayStr = date.toLocaleDateString(locale, { day: "numeric" }); // should we replace it for localized digits? - pattern = normalizeSpaces(pattern); return pattern.replace(dayStr, DAY_CODE); } diff --git a/src/mono/browser/runtime/hybrid-globalization/culture-info.ts b/src/mono/browser/runtime/hybrid-globalization/culture-info.ts index aa4e3f152d0d4..6c938198dabb7 100644 --- a/src/mono/browser/runtime/hybrid-globalization/culture-info.ts +++ b/src/mono/browser/runtime/hybrid-globalization/culture-info.ts @@ -4,7 +4,7 @@ import { VoidPtrNull } from "../types/internal"; import { runtimeHelpers } from "./module-exports"; import { Int32Ptr, VoidPtr } from "../types/emscripten"; -import { OUTER_SEPARATOR, normalizeLocale, normalizeSpaces } from "./helpers"; +import { OUTER_SEPARATOR, normalizeLocale } from "./helpers"; export function mono_wasm_get_culture_info (culture: number, cultureLength: number, dst: number, dstMaxLength: number, dstLength: Int32Ptr): VoidPtr { try { @@ -91,7 +91,7 @@ function getLongTimePattern (locale: string | undefined, designators: any): stri hourPattern = hasPrefix ? "hh" : "h"; pattern = pattern.replace(hasPrefix ? hour12WithPrefix : localizedHour12, hourPattern); } - return normalizeSpaces(pattern); + return pattern; } function getShortTimePattern (pattern: string): string { diff --git a/src/mono/browser/runtime/hybrid-globalization/helpers.ts b/src/mono/browser/runtime/hybrid-globalization/helpers.ts index 52e1943b0c58b..5bf28026404a9 100644 --- a/src/mono/browser/runtime/hybrid-globalization/helpers.ts +++ b/src/mono/browser/runtime/hybrid-globalization/helpers.ts @@ -26,15 +26,6 @@ export function normalizeLocale (locale: string | null) { } } -export function normalizeSpaces (pattern: string) { - if (!pattern.includes("\u202F") && !pattern.includes("\u00A0")) - return pattern; - - // Replace both \u202F and \u00A0 with a regular space \u0020 - return pattern.replace(/[\u202F\u00A0]/g, "\u0020"); -} - - export function isSurrogate (str: string, startIdx: number): boolean { return SURROGATE_HIGHER_START <= str[startIdx] && str[startIdx] <= SURROGATE_HIGHER_END && From 535a93110c882b424a0c129cc454e04a418bfd1e Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Thu, 13 Jun 2024 09:33:32 +0200 Subject: [PATCH 4/4] Apply feedback --- .../src/System/Globalization/CultureData.Icu.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Icu.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Icu.cs index 703ced9d15f5c..7bfd0826ae183 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Icu.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Icu.cs @@ -296,7 +296,12 @@ private unsafe string IcuGetTimeFormatString(bool shortFormat) if (GlobalizationMode.Hybrid) { string res = Interop.Globalization.GetLocaleTimeFormatNative(_sWindowsName, shortFormat); - span = res != null ? new ReadOnlySpan(ref res.GetRawStringData(), res.Length) : ReadOnlySpan.Empty; + if (string.IsNullOrEmpty(res)) + { + Debug.Fail("[CultureData.GetTimeFormatString(bool shortFormat)] Failed"); + return string.Empty; + } + span = res.AsSpan(); } else #endif