Repository navigation
Keep audit report export working when a violation carries invalid UTF-8 - #128
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
TypeFormatter previews string values with a byte-based substr(), which can split a multibyte character. json_encode() then fails on the malformed UTF-8 and exportReport()/writeWorkerShard() drop the whole report without any signal. Encode with JSON_INVALID_UTF8_SUBSTITUTE so the offending bytes become U+FFFD and the report is still written.
naxvog
force-pushed
the
fix/report-invalid-utf8
branch
from
November 11, 2026 08:35
8dd0ba7 to
a464d3f
Compare
rcalicdan
approved these changes
Nov 11, 2026
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.
Problem
In
reportmode, one violation can make the whole audit report disappear.TypeFormatter::formatGivenValue()previews long strings with a byte-basedsubstr($value, 0, 17). If byte 17 falls inside a multibyte character (umlauts, CJK, emoji), the preview is malformed UTF-8.json_encode()then returnsfalse,ViolationCollector::exportReport()returnsnull, and the shutdown handler ignores that result. No report file is written and nothing is printed. The same happens for worker shards inwriteWorkerShard(), and for any binary string value.Fix
Encode the report and the worker shards with
JSON_INVALID_UTF8_SUBSTITUTE. Malformed bytes become U+FFFD and the report is written.Verification
tests/Internal/Reporting/ViolationCollectorTest.phpbuilds the preview through the realTypeFormatterand exports both a report and a shard.Failed asserting that null is identical to '/tmp/…/typephp-report.json'. With the fix it passes.Not changed
The preview itself is still cut on a byte boundary, so a thrown
TypeErrormessage can still end in a partial character. Fixing that needsmbstring, which the package does not require.