A community user was reported that, it was used the Laravel with Guzzle PSR7 packages, while these wanna tracing the RequestException by the dd function, they got an exception message unreadble, and then try to respond it as JSON which got that Malformed UTF-8 characters, possibly incorrectly encoded fatal error.
Debugging that codes, the problem cames from Guzzle\Psr7\Message::bodySummary function with the default $truncateAt = 120 input.
Stream of the $truncateAt position that is in byte charcode, but the 120 index payload, it was the half of the multibyte chacracter. This is caused the UTF8 character malformed.
Possible solution is that, detect the $truncateAt character whether or nor is the multibyte, while it is true, extra offset 1 or 2 bytes as of the bodySummary respond.
PHP version: 8.3.0
Description
A community user was reported that, it was used the Laravel with Guzzle PSR7 packages, while these wanna tracing the
RequestException
by thedd
function, they got an exception message unreadble, and then try to respond it as JSON which got thatMalformed UTF-8 characters, possibly incorrectly encoded
fatal error.Debugging that codes, the problem cames from
Guzzle\Psr7\Message::bodySummary
function with the default$truncateAt = 120
input.For example, the
utf8
payload is:Stream of the
$truncateAt
position that is inbyte
charcode, but the120
index payload, it was the half of the multibyte chacracter. This is caused theUTF8
character malformed.Possible solution is that, detect the
$truncateAt
character whether or nor is the multibyte, while it is true, extra offset1
or2
bytes as of the bodySummary respond.This issue is samilar to #561 .