psr7 icon indicating copy to clipboard operation
psr7 copied to clipboard

summarize the multibytes(utf8) payload stream maybe cause the content unreadable

Open TheNorthMemory opened this issue 6 months ago • 0 comments

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 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.

unreadable-message

Debugging that codes, the problem cames from Guzzle\Psr7\Message::bodySummary function with the default $truncateAt = 120 input.

For example, the utf8 payload is:

'{"code":"PARAM_ERROR","detail":{"location":"body","value":""},"message":"输入源“/body/sub_mchid”映射到字段“子商户号/二级商户号”必填性规则校验失败,此字段为必填项"}'

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.

This issue is samilar to #561 .

TheNorthMemory avatar Dec 22 '23 06:12 TheNorthMemory