Skip to content

PHP 8.2: mb_convert_encoding(): Handling HTML entities via mbstring is deprecated #44281

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

Closed
Tracked by #44282
gharlan opened this issue Nov 25, 2021 · 5 comments
Closed
Tracked by #44282
Labels
Bug Help wanted Issues and PRs which are looking for volunteers to complete them. Status: Reviewed VarDumper

Comments

@gharlan
Copy link
Contributor

gharlan commented Nov 25, 2021

Symfony version(s) affected

4.4, 5.3, 5.4, 6.0

Description

Using the mbstring "encoding" HTML-ENTITIES is deprecated since PHP 8.2: php/php-src#7177

mb_convert_encoding(): Handling HTML entities via mbstring is deprecated; use htmlspecialchars, htmlentities, or mb_encode_numericentity/mb_decode_numericentity instead

These occurrences should be replaced: https://github.com/symfony/symfony/search?q=html-entities

How to reproduce

Use HtmlDumper from var-dumper component in php 8.2.

Possible Solution

No response

Additional Context

No response

@gharlan gharlan added the Bug label Nov 25, 2021
@derrabus derrabus added Status: Reviewed VarDumper Help wanted Issues and PRs which are looking for volunteers to complete them. and removed Status: Needs Review labels Nov 25, 2021
@derrabus
Copy link
Member

Confirmed.

@nicolas-grekas
Copy link
Member

@gharlan would you be able to work on a PR to get rid of this deprecation? It should target branch 4.4

@derrabus
Copy link
Member

@nicolas-grekas Why did you close the issue?

@nicolas-grekas
Copy link
Member

Bad button :)
But now that I think about it, we don't need an issue about that.
We already have a deprecation log in the CI.

@aleblanc
Copy link

Possible Solution:

$string = "<div><p>tèé Заматеріалами \"&'+</p></div>";

echo "Original:".mb_convert_encoding($string, 'HTML-ENTITIES', 'UTF-8');
echo "\n";
echo "Solution:".mb_encode_numericentity(
    htmlspecialchars_decode(
        htmlentities($string, ENT_NOQUOTES, 'UTF-8', false)
        ,ENT_NOQUOTES
    ), [0x80, 0x10FFFF, 0, ~0],
    'UTF-8'
);
echo "\n";

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Help wanted Issues and PRs which are looking for volunteers to complete them. Status: Reviewed VarDumper
Projects
None yet
Development

No branches or pull requests

5 participants