mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-22 06:42:41 +01:00
Fix PHP 8.0 ValueError calling mb_convert_encoding() with an invalid encoding
Summary: Per https://www.php.net/manual/en/function.mb-convert-encoding.php, as of PHP 8.0.0, a ValueError is thrown if the value of `to_encoding` or `from_encoding` is an invalid encoding but a ValueError is not suppressed by the stfu operator ("@"). Origin of the function: https://secure.phabricator.com/rPHU72ad8fd0f05b0d84f7d8efd7db62ad0b3ba4431f Premising that Arcanist elevates warnings to exception, now we just try-catch. Closes T15423 Test Plan: On `/diffusion/edit/1/page/encoding/`, * enter a valid encoding, such as "7bit", successfully changed encoding * enter a valid encoding with random capitalization, such as "7biT", successfully changed encoding * enter a valid alias encoding, such as "ISO-10646-UCS-2", successfully changed encoding * enter a valid alias encoding with random capitalization, such as "isO-10646-uCS-2", successfully changed encoding * enter an invalid encoding, such as "whatever", get error message "Repository encoding "whatever" is not valid: String conversion from encoding 'UTF-8' to encoding 'whatever' failed: mb_convert_encoding(): Argument #2 ($to_encoding) must be a valid encoding, "whatever" given" In any case, no exception is shown anymore. Reviewers: O1 Blessed Committers, valerio.bozzolan, speck Reviewed By: O1 Blessed Committers, valerio.bozzolan, speck Subscribers: 0, speck, tobiaswiese, valerio.bozzolan, Matthew, Cigaryno Maniphest Tasks: T15423 Differential Revision: https://we.phorge.it/D25249
This commit is contained in:
parent
6c6f47bf9c
commit
788098096e
1 changed files with 4 additions and 7 deletions
|
@ -718,13 +718,10 @@ function phutil_utf8_convert($string, $to_encoding, $from_encoding) {
|
||||||
'mbstring'));
|
'mbstring'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = @mb_convert_encoding($string, $to_encoding, $from_encoding);
|
try {
|
||||||
|
$result = mb_convert_encoding($string, $to_encoding, $from_encoding);
|
||||||
if ($result === false) {
|
} catch (Throwable $ex) {
|
||||||
$message = error_get_last();
|
$message = $ex->getMessage();
|
||||||
if ($message) {
|
|
||||||
$message = idx($message, 'message', pht('Unknown error.'));
|
|
||||||
}
|
|
||||||
throw new Exception(
|
throw new Exception(
|
||||||
pht(
|
pht(
|
||||||
"String conversion from encoding '%s' to encoding '%s' failed: %s",
|
"String conversion from encoding '%s' to encoding '%s' failed: %s",
|
||||||
|
|
Loading…
Reference in a new issue