Skip to content

Strip all whitespace from a pasted card number or ISBN [patch] - #477

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/476-identifier-whitespace
Oct 20, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/476-identifier-whitespace

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #476

What changed

CreditCardNumber and Isbn stripped only the ASCII space and -. A valid value with a trailing newline, a tab or a non-breaking space was therefore rejected with ArgumentException, even though Iban in the same package already strips every char.IsWhiteSpace character (#311).

  • A new internal IdentifierCanonicalization.StripWhitespaceAndHyphens is now the single place that decides what a separator is. Both types call it, so they can't drift apart again. Iban keeps its own loop because it doesn't strip hyphens.
  • The XML docs and the README normalisation table now say "whitespace". The Iban row, which said "spaces", is corrected as well.

Tests

  • CreditCardNumberTests.Create_WithWhitespace_StripsItAndValidates and IsbnTests.Create_WithWhitespace_StripsItAndValidates cover \n, \r\n, tab, NBSP, and mixed leading/trailing whitespace. The ISBN cases include a lowercase x check digit.
  • All 10 new cases fail on main and pass with the change. I checked this by reverting the two source files and re-running.
  • Full dotnet test on net10.0: 1793 passed, 12 skipped, 0 failed. The net8/net9 legs can't run here because those runtimes aren't installed; CI covers them.
  • dotnet build Semantics.Strings.Identifiers with .sonarlint/sonar-local.props: 0 warnings, 0 errors.

Generated by Claude Code

CreditCardNumber and Isbn removed only the ASCII space and `-`, so a valid
value carrying a trailing newline, a tab or a non-breaking space was
rejected, while Iban in the same package already stripped every
char.IsWhiteSpace character. Both now go through one shared
IdentifierCanonicalization helper so the two cannot drift apart again,
and the README table and XML docs say "whitespace".

Fixes #476

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VhcNHmVUqSbyA94vJQRrc5
@sonarqubecloud

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit e19ab1c into main Oct 20, 2026
16 checks passed
@matt-edmondson
matt-edmondson deleted the fix/476-identifier-whitespace branch October 20, 2026 11:46
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.

CreditCardNumber and Isbn reject a valid value pasted with a trailing newline, tab or non-breaking space, while Iban accepts the same input

1 participant