Skip to content

Reject codes with a trailing newline - #59

Merged
alcohol merged 1 commit into
mainfrom
fix-trailing-newline
Nov 2, 2026
Merged

alcohol merged 1 commit into
mainfrom
fix-trailing-newline

Conversation

@alcohol

@alcohol alcohol commented Nov 2, 2026

Copy link
Copy Markdown
Owner

In PCRE, $ also matches just before a final \n. So getByAlpha3("EUR\n"), getByNumeric("978\n") and getByCountry("NL\n") passed the format check, failed the lookup, and threw OutOfBoundsException ("does not contain") instead of DomainException ("Not a valid ...").

This anchors all three format regexes with \z instead of $, adds data-provider cases for each method, and adds a Fixed: line to the CHANGELOG under Unreleased.

Behaviour change: such input now throws DomainException. Both exceptions implement Alcohol\ISO4217\Exception, and neither input was ever a valid lookup. The new tests fail on the old regexes and pass with the fix, on PHP 8.5 (PHPUnit 12) and 7.4 (PHPUnit 9).

The CHANGELOG will conflict with #58 (both add a line under Unreleased). I'll rebase whichever merges second.

🤖 Generated with Claude Code

In PCRE, $ also matches before a final "\n", so "EUR\n", "978\n" and
"NL\n" passed the format checks and then threw OutOfBoundsException.
Anchor with \z so they throw DomainException like other malformed input.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (3e8d2f3) to head (0365772).

Additional details and impacted files
@@             Coverage Diff             @@
##                main       #59   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
  Complexity        17        17           
===========================================
  Files              1         1           
  Lines             32        32           
===========================================
  Hits              32        32           

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

@alcohol
alcohol merged commit 48cabf3 into main Nov 2, 2026
12 checks passed
@alcohol
alcohol deleted the fix-trailing-newline branch November 2, 2026 15:24
@alcohol alcohol mentioned this pull request Nov 2, 2026
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.

1 participant