Skip to content

fix: preserve explicit zero country-code presence - #518

Closed
wmundev wants to merge 1 commit into
mainfrom
fix/country-code-presence-20261106
Closed

wmundev wants to merge 1 commit into
mainfrom
fix/country-code-presence-20261106

Conversation

@wmundev

@wmundev wmundev commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator

Calling SetCountryCode(0) currently loses field presence: HasCountryCode returns false, merging the resulting number into a builder with country code 44 leaves 44 in place, and formatting an explicit zero-country/zero-national number as E164 returns an empty string instead of Java's +00. This is a verified P3, high-confidence parity defect affecting manually built partial numbers.

Track country-code presence separately from its integer value, including internal assignments, and clear both in ClearCountryCode. Merge and clone operations now retain an explicit zero. Equality and hashing continue to ignore country-code presence, following Java. This changes private storage and existing behavior only; no public member, metadata, regex, dependency, or Java-source changes.

Java reference: master 33be5664343676b27761213d8f5500d682568ea7. Phonenumber.java explicitly tracks presence in setCountryCode, clearCountryCode, and mergeFrom; exactlySameAs ignores this flag. PhoneNumberUtil.format tests presence when choosing the all-zero raw-input fallback. Existing upstream PhonenumberTest and PhoneNumberUtilTest were compared before adding the focused regressions.

Validation:

  • Five new regression/control tests cover explicit zero, builder property assignment, merge replacement, cloning/copying, clear, initialization, equality/hash behavior, and E164/raw-input output. Three failed before the fix on each modern TFM; all pass after.
  • Full solution: 1,184 passed, zero failures/skips (541 library + 51 extensions per net8/net10). All-framework build: zero warnings/errors, including modern trim/AOT analyzers and netstandard2.0.
  • Fresh unchanged Java executed 16 focused presence assertions and 1,109 formatting/validation cases producing 112,009 result entries. Compared actual hash-verified net8/net10/netstandard assets on a net10 host. All 46 country-code differences are resolved on every asset; no previously agreeing entry regressed. Modern assets have 12 pre-existing NANPA raw-input differences covered by closed, unmerged fix: preserve raw input for all-zero NANPA formatting #517; netstandard agrees on all entries. This PR does not include that independent fix.
  • Compared formatting, caller patterns/carrier codes, original/raw input, mobile/out-of-country dialing, validity, possibility/type, geography, and truncation for this corpus. Shared synthetic metadata blob 14fdad223881d77c7679cbf6e6e0eecc52e036f5 is identical. Shipped metadata remains C#9.0.42 / Java9.0.41; resources were not manually read or edited.
  • Release package/published-baseline API validation passed; clean same-path rebuild reproduces all three packaged library DLL hashes.
  • Diff whitespace check passed, preserving existing CRLF source files. Windows execution only; no runtime AOT/trim publish, Linux run, exhaustive production-metadata check, or whole-library parity claim.

Performance: repeated isolated BDN release measurements (in-process, 5 warmups, 10 requested 300ms iterations, one process per version) measured format 31.91→33.88ns, construction 4.01→4.37ns, copy 7.79→7.73ns, parse 352.52→415.54ns. Allocation remains 48/56/80/368B respectively. Outliers and especially the wide parse interval make throughput inconclusive; these samples are not a no-regression guarantee. CI benchmarks should be reviewed. C# main baseline: 2a0bb649a22a518ee74133fdbcebcf39f8ebbbd4.

@wmundev wmundev added the bug label Nov 6, 2026
@codecov

codecov Bot commented Nov 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.26%. Comparing base (2a0bb64) to head (f2fa353).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #518      +/-   ##
==========================================
+ Coverage   88.07%   88.26%   +0.18%     
==========================================
  Files          43       43              
  Lines        3891     3894       +3     
  Branches      993      993              
==========================================
+ Hits         3427     3437      +10     
+ Misses        264      255       -9     
- Partials      200      202       +2     

☔ 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.

@wmundev wmundev closed this Nov 6, 2026
@wmundev
wmundev deleted the fix/country-code-presence-20261106 branch November 6, 2026 01:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant