Replace utf8_encode() removed in PHP 8.2#433
Conversation
dregad
left a comment
There was a problem hiding this comment.
Thanks for your contribution @khushalVekariya.
This usage of utf8_encode() is present in the code since the initial contribution of the BitBucket plugin by @lazar2606 back in 2014 (see #98). I have to admit that I never really looked at that closely until now, as I do not use BitBucket myself.
Now that I did, I must say it actually feels wrong to call utf8_encode() here, because the JSON specification states that the data should already be UTF-8.
In fact, that reminds me of a case we had in MantisBT's JSON API many years ago, where calling utf8_encode() before sending content to json_decode() caused problems with Japanese strings (see #20350.
So I believe that the correct fix would be to remove the utf8_encode() call entirely:
- $t_json = json_decode( utf8_encode( $t_data ) );
+ $t_json = json_decode( $t_data );Could you test on your end and confirm it works without regressions ?
@dregad I don't use BitBucket myself — this PR was just aimed at fixing the PHP 8.2 compatibility violation, so I kept the behavior identical with mb_convert_encoding() as a drop-in replacement. Your point about RFC 7159 and the MantisBT #20350 precedent makes sense, but since removing utf8_encode() is a behavioral change (not just a compat fix) and I can't test it against BitBucket, I'd suggest tracking that as a separate issue. |
Just created #434 for this. |
Per JSON specification [1], data should already be UTF-8. Similar code was already changed in the same way in MantisBT a few years ago, see issue #20350 [2] Fixes #434, follow-up on #433 [1]: https://www.rfc-editor.org/rfc/rfc7159#section-8.1 [2]: https://mantisbt.org/bugs/view.php?id=20350
Summary
utf8_encode()was deprecated in PHP 8.2 and removed in later versions, causing a fatal error when the BitBucket integration callsapi_json_url()on modern PHP.SourceBitBucketPlugin::api_json_url()withmb_convert_encoding($data, 'UTF-8', 'ISO-8859-1'), which the PHP manual lists as the direct equivalent.Why
MantisBT plugins targeting current PHP releases were breaking when BitBucket returned non-ASCII bytes (commit messages, author names, etc.) because
utf8_encode()no longer exists.