Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 30, 2026

Description

BigInteger parsing fails for UTF-8 byte arrays with Ukrainian culture (uk-UA) when using NumberStyles.AllowThousands. Ukrainian uses NBSP (U+00A0) as NumberGroupSeparator, but users type regular space (U+0020).

The MatchChars function in Number.Parsing.Common.cs had incomplete space equivalence logic:

  • Handled NBSP→space direction only for char (UTF-16)
  • Missing space→NBSP direction
  • No UTF-8 multi-byte sequence support (NBSP = 0xC2 0xA0, narrow NBSP = 0xE2 0x80 0xAF)

Changes

Core parsing (Number.Parsing.Common.cs):

  • Added bidirectional space-replacing character equivalence for char path
  • Implemented UTF-8 multi-byte handling for NBSP (0xC2 0xA0) and narrow NBSP (0xE2 0x80 0xAF)
  • Updated comments to reference all cultures using space-replacing separators

Testing (parse.ukUA.cs):

  • Added tests validating UTF-8/string parsing parity with Ukrainian culture
  • Covers trailing spaces and NBSP character handling

Example

var ukCulture = new CultureInfo("uk-UA");
CultureInfo.CurrentCulture = ukCulture;

// Previously failed, now works
byte[] utf8 = Encoding.UTF8.GetBytes("123 ");  // trailing space
var result = BigInteger.Parse(utf8, NumberStyles.AllowTrailingWhite);  // ✓

// NBSP also works
byte[] utf8Nbsp = Encoding.UTF8.GetBytes("1\u00a0234\u00a0567");
result = BigInteger.Parse(utf8Nbsp, NumberStyles.AllowThousands);  // ✓
Original prompt

This section details on the original issue you should resolve

<issue_title>System.Numerics.Tests.parseTest.RunParseToStringTests(culture: uk-UA) test failures</issue_title>
<issue_description>This test runs as part of the libraries outer loop.

Hit in #119427. Log file: https://helixr1107v0xdcypoyl9e7f.blob.core.windows.net/dotnet-runtime-refs-pull-119427-merge-e179d39d041e4c21b3/System.Runtime.Numerics.Tests/1/console.8967a987.log?skoid=8eda00af-b5ec-4be9-b69b-0919a2338892&sktid=72f988bf-86f1-41af-91ab-2d7cd011db47&skt=2025-10-01T01%3A05%3A30Z&ske=2025-10-01T02%3A05%3A30Z&sks=b&skv=2024-11-04&sv=2024-11-04&st=2025-10-01T01%3A05%3A30Z&se=2025-10-01T02%3A05%3A30Z&sr=c&sp=r&sig=7IW6R8WrZP0cNbaHbzQaVlxd8lGUkdAbHB4%2BpInETpk%3D

    System.Numerics.Tests.parseTest.RunParseToStringTests(culture: uk-UA) [FAIL]
      System.FormatException : The value could not be parsed.
      Stack Trace:
        /_/src/libraries/System.Runtime.Numerics/src/System/Number.BigInteger.cs(29,0): at System.Number.ThrowOverflowOrFormatException(ParsingStatus status)
        /_/src/libraries/System.Runtime.Numerics/src/System/Number.BigInteger.cs(136,0): at System.Number.ParseBigInteger[TChar](ReadOnlySpan`1 value, NumberStyles style, NumberFormatInfo info)
        /_/src/libraries/System.Runtime.Numerics/src/System/Numerics/BigInteger.cs(707,0): at System.Numerics.BigInteger.Parse(ReadOnlySpan`1 utf8Text, NumberStyles style, IFormatProvider provider)
        /_/src/libraries/System.Runtime.Numerics/tests/BigInteger/parse.cs(828,0): at System.Numerics.Tests.parseTest.VerifyParseSpanToString(String num1, NumberStyles ns, Boolean failureNotExpected, String expected)
        /_/src/libraries/System.Runtime.Numerics/tests/BigInteger/parse.cs(884,0): at System.Numerics.Tests.parseTest.VerifyParseToString(String num1, NumberStyles ns, Boolean failureNotExpected, String expected)
        /_/src/libraries/System.Runtime.Numerics/tests/BigInteger/parse.cs(818,0): at System.Numerics.Tests.parseTest.VerifyParseToString(String num1, NumberStyles ns, Boolean failureNotExpected)
        /_/src/libraries/System.Runtime.Numerics/tests/BigInteger/parse.cs(689,0): at System.Numerics.Tests.parseTest.VerifyNumberStyles(NumberStyles ns, Random random)
        /_/src/libraries/System.Runtime.Numerics/tests/BigInteger/parse.cs(52,0): at System.Numerics.Tests.parseTest.RunParseToStringTests(CultureInfo culture)
           at InvokeStub_parseTest.RunParseToStringTests(Object, Span`1)
        /_/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodBaseInvoker.cs(95,0): at System.Reflection.MethodBaseInvoker.InvokeWithOneArg(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
    System.Numerics.Tests.parseTestThreshold.RunParseToStringTests(culture: uk-UA) [FAIL]
      System.FormatException : The value could not be parsed.
      Stack Trace:
        /_/src/libraries/System.Runtime.Numerics/src/System/Number.BigInteger.cs(29,0): at System.Number.ThrowOverflowOrFormatException(ParsingStatus status)
        /_/src/libraries/System.Runtime.Numerics/src/System/Number.BigInteger.cs(136,0): at System.Number.ParseBigInteger[TChar](ReadOnlySpan`1 value, NumberStyles style, NumberFormatInfo info)
        /_/src/libraries/System.Runtime.Numerics/src/System/Numerics/BigInteger.cs(707,0): at System.Numerics.BigInteger.Parse(ReadOnlySpan`1 utf8Text, NumberStyles style, IFormatProvider provider)
        /_/src/libraries/System.Runtime.Numerics/tests/BigInteger/parse.cs(828,0): at System.Numerics.Tests.parseTest.VerifyParseSpanToString(String num1, NumberStyles ns, Boolean failureNotExpected, String expected)
        /_/src/libraries/System.Runtime.Numerics/tests/BigInteger/parse.cs(884,0): at System.Numerics.Tests.parseTest.VerifyParseToString(String num1, NumberStyles ns, Boolean failureNotExpected, String expected)
        /_/src/libraries/System.Runtime.Numerics/tests/BigInteger/parse.cs(818,0): at System.Numerics.Tests.parseTest.VerifyParseToString(String num1, NumberStyles ns, Boolean failureNotExpected)
        /_/src/libraries/System.Runtime.Numerics/tests/BigInteger/parse.cs(689,0): at System.Numerics.Tests.parseTest.VerifyNumberStyles(NumberStyles ns, Random random)
        /_/src/libraries/System.Runtime.Numerics/tests/BigInteger/parse.cs(52,0): at System.Numerics.Tests.parseTest.RunParseToStringTests(CultureInfo culture)
        /_/src/libraries/System.Runtime.Numerics/tests/BigInteger/parse.cs(1349,0): at System.Numerics.Tests.parseTestThreshold.<>c__DisplayClass2_0.<RunParseToStringTests>b__1()
        /_/src/libraries/System.Runtime.Numerics/tests/BigInteger/BigIntTools.cs(54,0): at BigIntTools.Utils.RunWithFakeThreshold(Int32& field, Int32 value, Action action)
        /_/src/libraries/System.Runtime.Numerics/tests/BigInteger/parse.cs(1347,0): at System.Numerics.Tests.parseTestThreshold.<>c__DisplayClass2_0.<RunParseToStringTests>b__0()
        /_/src/libraries/System.Runtime....

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

- Fixes dotnet/runtime#120283

<!-- START COPILOT CODING AGENT TIPS -->
---

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more [Copilot coding agent tips](https://gh.io/copilot-coding-agent-tips) in the docs.

Copilot AI and others added 4 commits January 30, 2026 02:00
Co-authored-by: artl93 <9855795+artl93@users.noreply.github.com>
Co-authored-by: artl93 <9855795+artl93@users.noreply.github.com>
Co-authored-by: artl93 <9855795+artl93@users.noreply.github.com>
Co-authored-by: artl93 <9855795+artl93@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix System.Numerics.Tests parseTest failures for culture uk-UA Fix BigInteger UTF-8 parsing with Ukrainian culture NBSP handling Jan 30, 2026
Copilot AI requested a review from artl93 January 30, 2026 02:43
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.

2 participants