Fix PHP 8.6 mb_regex_encoding deprecation in domain validation (#57) - #58
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #58 +/- ##
============================================
+ Coverage 91.99% 93.06% +1.07%
+ Complexity 382 380 -2
============================================
Files 6 6
Lines 987 981 -6
============================================
+ Hits 908 913 +5
+ Misses 79 68 -11
🚀 New features to boost your workflow:
|
validateDomainName() called mb_regex_encoding()/mb_split(), both of which
emit E_DEPRECATED under PHP 8.6 (the underlying oniguruma library is
unmaintained). The domain is already ASCII at that point (post-punycode,
via normalizeDomainAscii()), so label splitting now uses explode('.') and
the hyphen-boundary checks use substr() instead of mb_substr(). The unused
$encoding parameter is dropped — the sole caller never passed it. Behavior
is unchanged. Two now-stale psalm-baseline entries are removed.
CI: extend the test matrix to PHP 8.5 (required) and 8.6 (experimental,
continue-on-error against nightly with --ignore-platform-req=php+), so
removed/deprecated functions surface early without nightly breakage blocking
PRs. Composer cache is now keyed per PHP version.
Test coverage for the touched code and the MB/encoding paths around it:
- testspec: trailing-hyphen label, invalid-char label, over-255 domain
- non-UTF-8 tokenizer (ISO-8859-1) and variable-width (Shift-JIS) parsing
- RFC 5321 length boundaries: accept-at-max, reject-one-over
- PunycodeConversionFailed and LocalPartCannotBeNormalized (previously
never triggered by any functional test)
- mismatched caller-encoding domain fails gracefully
- malformed-UTF-8 handling gated on a runtime mbstring probe: 8.1/8.2
preserve invalid bytes (rejected), 8.3+ substitute them during
tokenization before the guard runs
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
mmucklo
force-pushed
the
fix/57-mb-regex-deprecation
branch
from
July 13, 2026 00:32
0e841cd to
ca0a0f8
Compare
mmucklo
added a commit
that referenced
this pull request
Jul 13, 2026
…58) validateDomainName() called mb_regex_encoding()/mb_split(), both of which emit E_DEPRECATED under PHP 8.6 (the underlying oniguruma library is unmaintained). The domain is already ASCII at that point (post-punycode, via normalizeDomainAscii()), so label splitting now uses explode('.') and the hyphen-boundary checks use substr() instead of mb_substr(). The unused $encoding parameter is dropped — the sole caller never passed it. Behavior is unchanged. Two now-stale psalm-baseline entries are removed. CI: extend the test matrix to PHP 8.5 (required) and 8.6 (experimental, continue-on-error against nightly with --ignore-platform-req=php+), so removed/deprecated functions surface early without nightly breakage blocking PRs. Composer cache is now keyed per PHP version. Test coverage for the touched code and the MB/encoding paths around it: - testspec: trailing-hyphen label, invalid-char label, over-255 domain - non-UTF-8 tokenizer (ISO-8859-1) and variable-width (Shift-JIS) parsing - RFC 5321 length boundaries: accept-at-max, reject-one-over - PunycodeConversionFailed and LocalPartCannotBeNormalized (previously never triggered by any functional test) - mismatched caller-encoding domain fails gracefully - malformed-UTF-8 handling gated on a runtime mbstring probe: 8.1/8.2 preserve invalid bytes (rejected), 8.3+ substitute them during tokenization before the guard runs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #57.
Problem
validateDomainName()usedmb_regex_encoding()+mb_split()to split the domain into labels. Both emitE_DEPRECATEDunder PHP 8.6 (the underlying oniguruma library is no longer maintained):Fix
At that point the domain is already pure ASCII — it has been through
idn_to_ascii()vianormalizeDomainAscii()— so the multibyte machinery buys nothing:mb_split('\.', $domain)→explode('.', $domain)mb_substr($part, …, $encoding)hyphen-boundary checks →substr()$encodingparameter — the sole caller (Parse.php) never passed it, so it was always the'UTF-8'defaultBehavior is unchanged. Two now-stale
psalm-baseline.xmlentries (the removedmb_regex_encodingcalls) are cleaned up.Tests
Filled coverage gaps around the touched code and the MB/encoding paths it sits in — each assertion captured from the real parser output, not guessed:
Domain-label branches (testspec.yml)
baddomain-.com) — thesubstr($part, -1)half of the boundary check had no testbad_domain.com) — the per-labelpreg_matchbranchdomain_too_long)Encoding / MB (ParseTest.php)
mb_substrindexes by character, not byteInvalidUtf8Encoding)PunycodeConversionFailedandLocalPartCannotBeNormalized— previously referenced only in the severity-enum test, never triggered functionallyAlso documented in-source that the empty-label branch in
validateDomainNameis unreachable (the state machine rejects consecutive/edge dots first).Verification
All green:
composer test(91 tests, 3325 assertions),composer stan(PHPStan level 8),composer psalm,composer cs:check.