New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid json_encode when serializing non-UTF8 literals #7791
Conversation
`\Psalm\Internal\Clause::$hash` basically holds a hash on arbitrary input literals, used for later comparison. Using `json_encode` fails when dealing with non-UTF8 literals, which has been replaced by plain PHP `serialize`. Resolves: vimeo#7771
This change does not actually crash in the 4.x branch - errors in |
This is interesting because it means those hash are returned as false on 4.x. Meaning whatever use we make of those hash could be completely bogus (for example when two weird encoded string need to be hashed) This is a potential bug revealed by @weirdan applying a rector rule here: #7303 /cc @TomasVotruba :) |
I'd go with |
Unfortunately Seems like I need to check JSON specs carefully on that topic, since in JavaScript the following seems to be fine... JSON.stringify(String.fromCharCode(255)) |
If serialize is working fine, I'm good with it :) |
There is
The JavaScript implementation is wrong, it must be UTF-8:
Although technically the various JS implementations probably predate that RFC. RFC 7159 says:
So it's less "wrong" and more "not fully up to date with the latest RFC", and unfortunately it will probably always be that way because JS is nearly impossible to change without breaking compatibility with half the internet. |
Related: vimeo#7771
Thanks! |
Avoid json_encode when serializing non-UTF8 literals
ℹ️ Merged to |
\Psalm\Internal\Clause::$hash
basically holds a hash on arbitrary input literals, used for later comparison. Usingjson_encode
fails when dealing with non-UTF8 literals, which has been replaced by plain PHPserialize
.Resolves: #7771