Skip to content
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

Malformed UTF-8 characters, possibly incorrectly encoded #151

Open
guldil opened this issue Jul 3, 2024 · 1 comment
Open

Malformed UTF-8 characters, possibly incorrectly encoded #151

guldil opened this issue Jul 3, 2024 · 1 comment

Comments

@guldil
Copy link

guldil commented Jul 3, 2024

Hello,

First time after 18 months i got this error.

I'm exporting billing details with $detail = $conn->get('/me/bill/' . $id . '/details/' . $detailid);

Today on my VOIP invoice i got error : "Malformed UTF-8 characters, possibly incorrectly encoded"

After some debug with ChatGPT it's come from this kind of detail :

string(278) "{"periodEnd":"2024-08-01","totalPrice":{"currencyCode":"EUR","value":0,"text":"0.00 €"},"quantity":"1","periodStart":"2024-07-01","domain":"XXXXXXXXXXXXX","billDetailId":"XXXXXXXXXXXX","unitPrice":{"text":"0 €","currencyCode":"EUR","value":0},"description":"Un num▒ro port▒"}"

chatGPT rewrote the function :

private function decodeResponse(Response $response)
{
    if ($response->getStatusCode() === 204 || $response->getBody()->getSize() === 0) {
        return null;
    }
    $response->getBody()->rewind();
    try {
        $bodyContent = $response->getBody()->getContents();
        if (!mb_check_encoding($bodyContent, 'UTF-8')) {
            $bodyContent = mb_convert_encoding($bodyContent, 'UTF-8', 'ISO-8859-1'); // Exemple de conversion
            if (!mb_check_encoding($bodyContent, 'UTF-8')) {
                throw new \Exception('Failed to convert response body to valid UTF-8');
            }
        }

        return json_decode($bodyContent, true, 512, JSON_THROW_ON_ERROR);
    } catch (\Exception $e) {
        var_dump($response->getBody()->getSize());
        var_dump($response->getStatusCode());

        // Réinitialiser le curseur du flux avant de le lire à nouveau pour le débogage
        $response->getBody()->rewind();
        var_dump($response->getBody()->getContents());

        die($e->getMessage());
    }
}`

Thanks

Guldil
@deathiop
Copy link
Contributor

deathiop commented Jul 4, 2024

Hi there,

We got an internal issue that led to some failures regarding some UTF8 data.
This should now be fixed, could you please give it a retry and give us some feedback please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants