You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
From my perspective it looks good, but the AI requests one change:
fromHex('C2') is now accepted because mb_strlen("\xC2", 'UTF-8') === 1, but it is a truncated UTF‑8 lead byte. Then toUnicode() reads a missing continuation byte as zero and returns 128 (U+0080)—silently turning malformed input into a valid, different character.
The new constructor/fromHex behavior needs either strict UTF‑8 validation or length/continuation-byte validation in toUnicode() that returns -1 for truncated sequences. A regression test for Char::fromHex('C2')->toUnicode() is important.
Otherwise, the core direction looks good: permitting a single multibyte UTF‑8 character fixes the previous byte-length limitation, and changing the invalid-leading-byte return from false to -1 matches the declared int return type. The added valid 2-, 3-, and 4-byte coverage is useful.
Could you please double-check this and especially add this regression test?
The prior blocker is resolved. C2 now correctly returns -1, and the regression test covers it.
I would still request one change if this PR intends UTF‑8 Char support:
toHex() still delegates to toAscii(), which returns only the first byte. Consequently:
Char::fromHex('C2A2')->toHex(); // "C2", not "C2A2"
new Char('€')->toHex(); // "E2", not "E282AC"
That makes the newly supported multibyte fromHex() non-round-trippable and contradicts “hexadecimal value of the char.” toHex() should encode the complete stored byte string (e.g. uppercase bin2hex($this->char)), with a multibyte round-trip test.
Aside from that, the updated toUnicode() validation looks good: it checks expected byte length, validates continuation bytes, fixes the four-byte mask, and preserves the -1 invalid-input convention.
Rechecked the latest head (82880f7)—both prior issues are fixed.
Truncated UTF‑8 sequences return -1, with a regression test.
toHex() now encodes all bytes, and multibyte UTF‑8 round-trips are tested.
The updated source passed syntax validation and focused checks for ASCII, valid 2/3/4-byte code points, invalid leads, truncation, and hex round-trip.
I don’t see any remaining merge-blocking issue. The only tiny nit is an old test comment saying invalid leading bytes “should return false” while assertions correctly expect -1; that can be cleaned up separately.
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
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.
Description
Add Tests to CharTest.php and fix related errors.
Changes Made
Fix issues like this
Changes covered in
public function testUnicode1Byte()Additional Notes
Maybe separate 2Byte, 3Byte and 4Byte test in separate functions.
Merge Request Checklists