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

[4.2] PHP8.2 Replace deprecated utf8 encode/decode to mb string #39583

Merged
merged 7 commits into from Jan 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion components/com_users/src/Model/ProfileModel.php
Expand Up @@ -130,7 +130,8 @@ public function getForm($data = [], $loadData = true)
$username = $loadData ? $form->getValue('username') : $this->loadFormData()->username;

if ($username) {
$isUsernameCompliant = !(preg_match('#[<>"\'%;()&\\\\]|\\.\\./#', $username) || strlen(utf8_decode($username)) < 2
$isUsernameCompliant = !(preg_match('#[<>"\'%;()&\\\\]|\\.\\./#', $username)
|| strlen(mb_convert_encoding($username, 'ISO-8859-1', 'UTF-8')) < 2
laoneo marked this conversation as resolved.
Show resolved Hide resolved
|| trim($username) !== $username);
}

Expand Down
1 change: 1 addition & 0 deletions composer.json
Expand Up @@ -79,6 +79,7 @@
"symfony/error-handler": "^5.2",
"symfony/ldap": "~5.0",
"symfony/options-resolver": "~5.0",
"symfony/polyfill-mbstring": "^1.27",
"symfony/polyfill-php73": "^1.10",
"symfony/web-link": "~5.0",
"symfony/yaml": "~5.0",
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions installation/src/Form/Rule/UsernameRule.php
Expand Up @@ -43,9 +43,10 @@ public function test(\SimpleXMLElement $element, $value, $group = null, Registry
$filterInput = InputFilter::getInstance();

if (
preg_match('#[<>"\'%;()&\\\\]|\\.\\./#', $value) || strlen(utf8_decode($value)) < 2
preg_match('#[<>"\'%;()&\\\\]|\\.\\./#', $value)
|| strlen(mb_convert_encoding($value, 'ISO-8859-1', 'UTF-8')) < 2
|| $filterInput->clean($value, 'TRIM') !== $value
|| strlen(utf8_decode($value)) > $element['size']
|| strlen(mb_convert_encoding($value, 'ISO-8859-1', 'UTF-8')) > $element['size']
) {
return false;
}
Expand Down
6 changes: 3 additions & 3 deletions libraries/src/Filter/InputFilter.php
Expand Up @@ -435,7 +435,7 @@ protected function decode($source)
$trans_tbl = get_html_translation_table(HTML_ENTITIES, ENT_COMPAT, 'ISO-8859-1');

foreach ($trans_tbl as $k => $v) {
$ttr[$v] = utf8_encode($k);
$ttr[$v] = mb_convert_encoding($k, 'UTF-8', 'ISO-8859-1');
}
}

Expand All @@ -445,7 +445,7 @@ protected function decode($source)
$source = preg_replace_callback(
'/&#(\d+);/m',
function ($m) {
return utf8_encode(\chr($m[1]));
return mb_convert_encoding(\chr($m[1]), 'UTF-8', 'ISO-8859-1');
},
$source
);
Expand All @@ -454,7 +454,7 @@ function ($m) {
$source = preg_replace_callback(
'/&#x([a-f0-9]+);/mi',
function ($m) {
return utf8_encode(\chr('0x' . $m[1]));
return mb_convert_encoding(\chr('0x' . $m[1]), 'UTF-8', 'ISO-8859-1');
},
$source
);
Expand Down