fix: correct PHP serializer/unserializer bugs (closes #8)#19
Merged
Conversation
- Add O: (PHP object) support to unserializeValue; previously threw
'Unsupported or invalid serialized format' for any O: input
- Fix serializeValue to emit O: format when input object has __class
- Handle PHP special float values: d:INF;, d:-INF;, d:NAN;
(parseFloat('INF') returns NaN in JS — now handled explicitly)
- Fix empty array deserialization: a:0:{} now returns [] not {}
(previous code had 'isSequentialArray && length > 0' guard)
- Remove incorrect input.trim() in unserializeValue — trimming shifts
byte positions, breaking UTF-8 s: string length parsing
- Add proper UTF-8 byte-aware s: string decoder (Uint8Array path)
so multi-byte characters are measured and parsed by byte length
- Add PhpSerializer.test.mjs (27 assertions, runs with plain node)
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
|
Claude encountered an error —— View job I'll analyze this and get back to you. |
nadimtuhin
added a commit
that referenced
this pull request
Jun 28, 2026
- Add O: (PHP object) support to unserializeValue; previously threw
'Unsupported or invalid serialized format' for any O: input
- Fix serializeValue to emit O: format when input object has __class
- Handle PHP special float values: d:INF;, d:-INF;, d:NAN;
(parseFloat('INF') returns NaN in JS — now handled explicitly)
- Fix empty array deserialization: a:0:{} now returns [] not {}
(previous code had 'isSequentialArray && length > 0' guard)
- Remove incorrect input.trim() in unserializeValue — trimming shifts
byte positions, breaking UTF-8 s: string length parsing
- Add proper UTF-8 byte-aware s: string decoder (Uint8Array path)
so multi-byte characters are measured and parsed by byte length
- Add PhpSerializer.test.mjs (27 assertions, runs with plain node)
Co-authored-by: Claude <claude@anthropic.com>
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.
Summary
Fixes all PHP serializer/unserializer bugs reported in #8.
Bugs fixed
1. PHP objects (O: format) — throws "Unsupported or invalid serialized format"
Unserializer now correctly parses
O:8:"stdClass":1:{s:4:"prop";i:1;}into{__class:"stdClass",prop:1}.2. Special PHP float values — d:INF;, d:-INF;, d:NAN;
parseFloat('INF')returnsNaNin JS, causing the parser to throw "Invalid double value".Now handled explicitly:
d:INF;→Infinity,d:-INF;→-Infinity,d:NAN;→NaN.3. Empty array — a:0:{} returned {} instead of []
Previous code had guard
isSequentialArray && length > 0, meaning empty arrays fell through to the object path.Now
length === 0 || isSequentialArraycorrectly returns[].4. input.trim() in unserializer broke UTF-8 string byte positions
Removed. PHP
s:format uses byte length, so trimming before parsing would shift positions for strings with leading whitespace (valid in serialized data embedded in other strings).5. Serializer: Infinity/NaN emitted as invalid d: values
Now serializes
Infinity→d:INF;,-Infinity→d:-INF;,NaN→d:NAN;.6. Object serializer now emits O: format
Objects with a
__classproperty now serialize asO:(PHP object) rather thana:(PHP array).Testing
Added
PhpSerializer.test.mjs— 27 assertions covering all PHP types. Run with plain node (no framework):Closes #8