Skip to content

Commit fe1122b

Browse files
committed
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 <freebsd#2> PhutilErrorHandler::handleError(integer, string, string, integer, array) called at [<arcanist>/src/error/PhutilErrorHandler.php:261] freebsd#1 <freebsd#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
1 parent 2295bcd commit fe1122b

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/applications/files/document/PhabricatorTextDocumentEngine.php

+10-4
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,16 @@ protected function loadTextData(PhabricatorDocumentRef $ref) {
7070
$encoding = $this->getEncodingConfiguration();
7171
if ($encoding !== null) {
7272
if (function_exists('mb_convert_encoding')) {
73-
$content = mb_convert_encoding($content, 'UTF-8', $encoding);
74-
$this->encodingMessage = pht(
75-
'This document was converted from %s to UTF8 for display.',
76-
$encoding);
73+
try {
74+
$content = mb_convert_encoding($content, 'UTF-8', $encoding);
75+
$this->encodingMessage = pht(
76+
'This document was converted from %s to UTF8 for display.',
77+
$encoding);
78+
} catch (Throwable $ex) {
79+
$this->encodingMessage = pht(
80+
'Unable to convert from requested encoding %s to UTF8.',
81+
$encoding);
82+
}
7783
} else {
7884
$this->encodingMessage = pht(
7985
'Unable to perform text encoding conversion: mbstring extension '.

0 commit comments

Comments
 (0)