Skip to content

fix: normalize only Unicode decimal digits - #505

Merged
wmundev merged 3 commits into
mainfrom
codex/fix-unicode-digit-normalization
Oct 19, 2026
Merged

wmundev merged 3 commits into
mainfrom
codex/fix-unicode-digit-normalization

Conversation

@wmundev

@wmundev wmundev commented Oct 18, 2026

Copy link
Copy Markdown
Collaborator

NormalizeDigitsOnly("\u0BF1123") throws on modern targets because Tamil hundred expands into three ASCII digits inside an input-sized buffer. Other numeric symbols can also introduce digits that Java excludes.

Use Unicode decimal-digit values in both the span and StringBuilder implementations, matching Java's Character.digit(c, 10). Each accepted character now produces one ASCII digit; non-decimal numeric characters are stripped or retained according to keepNonDigits.

Regression coverage includes Tamil hundred, fractions, Roman numerals, superscripts, circled numbers, and a negative numeric value. It also verifies Arabic-Indic, Devanagari and fullwidth decimal digits, both stack and pooled inputs, and the shared StringBuilder helper.

Upstream behavior: https://github.com/google/libphonenumber/blob/33be5664343676b27761213d8f5500d682568ea7/java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java#L825-L837

Validation:

  • Confirmed the non-decimal regression fails before the fix; decimal-digit preservation passes before and after.
  • Full solution test matrix: 998 passing executions across .NET 8 and .NET 10.
  • All target frameworks build with zero warnings and errors.
  • Robustness tests run directly against netstandard2.0 on both runtimes: 20 passing executions for this branch.
  • All three fixes apply together without conflicts; combined matrix passes 1,006 executions, plus 28 robustness executions directly against netstandard2.0.
  • BenchmarkDotNet ParseOnly comparison completed: allocation stayed at 348.13 KB per 1,000 numbers. Short timing samples were too noisy to establish a throughput change.

Match Java Character.digit(c, 10) in both span and StringBuilder normalization, preventing numeric symbols from expanding beyond the input buffer. Cover non-decimal numerics, Unicode decimal digits and both stack and pooled inputs.

Upstream reference: https://github.com/google/libphonenumber/blob/33be5664343676b27761213d8f5500d682568ea7/java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java#L825-L837
@codecov

codecov Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.91%. Comparing base (387caaf) to head (81b25cd).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #505      +/-   ##
==========================================
- Coverage   87.92%   87.91%   -0.02%     
==========================================
  Files          43       43              
  Lines        3900     3896       -4     
  Branches      995      995              
==========================================
- Hits         3429     3425       -4     
  Misses        272      272              
  Partials      199      199              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread csharp/PhoneNumbers.Test/TestPublicApiRobustness.cs Fixed
Comment thread csharp/PhoneNumbers.Test/TestPublicApiRobustness.cs Fixed
Comment thread csharp/PhoneNumbers.Test/TestPublicApiRobustness.cs Fixed
@wmundev
wmundev marked this pull request as ready for review October 18, 2026 06:39
@wmundev
wmundev requested a review from twcclegg as a code owner October 18, 2026 06:39
@wmundev
wmundev merged commit 77b2c25 into main Oct 19, 2026
9 checks passed
@wmundev
wmundev deleted the codex/fix-unicode-digit-normalization branch October 19, 2026 11:06
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.

3 participants