mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-25 08:12:40 +01:00
Catch RuntimeException: mb_convert_encoding(): Illegal character encoding specified at PhabricatorTextDocumentEngine.php:73
Summary: When given `$encoding` is invalid, catch the exception to show a proper error message and make the server logs provide more hints. ``` EXCEPTION: (RuntimeException) mb_convert_encoding(): Illegal character encoding specified at [<arcanist>/src/error/PhutilErrorHandler.php:261] #0 <#2> PhutilErrorHandler::handleError(integer, string, string, integer, array) called at [<arcanist>/src/error/PhutilErrorHandler.php:261] #1 <#2> mb_convert_encoding(string, string, string) called at [<phabricator>/src/applications/files/document/PhabricatorTextDocumentEngine.php:73] ``` Closes T15624 Test Plan: Open a URL which passes a bogus encoding value as parameter, like `/source/somerepository/browse/master/README.md?as=source&encode=TROLOLOL` Reviewers: O1 Blessed Committers, valerio.bozzolan Reviewed By: O1 Blessed Committers, valerio.bozzolan Subscribers: Sten, tobiaswiese, valerio.bozzolan, Matthew, Cigaryno Maniphest Tasks: T15624 Differential Revision: https://we.phorge.it/D25418
This commit is contained in:
parent
2295bcda14
commit
fe1122bd4d
1 changed files with 10 additions and 4 deletions
|
@ -70,10 +70,16 @@ abstract class PhabricatorTextDocumentEngine
|
||||||
$encoding = $this->getEncodingConfiguration();
|
$encoding = $this->getEncodingConfiguration();
|
||||||
if ($encoding !== null) {
|
if ($encoding !== null) {
|
||||||
if (function_exists('mb_convert_encoding')) {
|
if (function_exists('mb_convert_encoding')) {
|
||||||
|
try {
|
||||||
$content = mb_convert_encoding($content, 'UTF-8', $encoding);
|
$content = mb_convert_encoding($content, 'UTF-8', $encoding);
|
||||||
$this->encodingMessage = pht(
|
$this->encodingMessage = pht(
|
||||||
'This document was converted from %s to UTF8 for display.',
|
'This document was converted from %s to UTF8 for display.',
|
||||||
$encoding);
|
$encoding);
|
||||||
|
} catch (Throwable $ex) {
|
||||||
|
$this->encodingMessage = pht(
|
||||||
|
'Unable to convert from requested encoding %s to UTF8.',
|
||||||
|
$encoding);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$this->encodingMessage = pht(
|
$this->encodingMessage = pht(
|
||||||
'Unable to perform text encoding conversion: mbstring extension '.
|
'Unable to perform text encoding conversion: mbstring extension '.
|
||||||
|
|
Loading…
Reference in a new issue