@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+10 -4
+10 -4
src/applications/files/document/PhabricatorTextDocumentEngine.php
··· 70 70 $encoding = $this->getEncodingConfiguration(); 71 71 if ($encoding !== null) { 72 72 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 + } 77 83 } else { 78 84 $this->encodingMessage = pht( 79 85 'Unable to perform text encoding conversion: mbstring extension '.