mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-29 10:12:41 +01:00
Use phutil_utf8_convert() in Phabricator
Summary: See D3252. Test Plan: This one is nasty to test, I'm going to make some coffee first. Reviewers: davidreuss, vrana, btrahan Reviewed By: davidreuss CC: aran Maniphest Tasks: T452 Differential Revision: https://secure.phabricator.com/D3254
This commit is contained in:
parent
a8a4e85443
commit
3e29921f5e
3 changed files with 8 additions and 16 deletions
|
@ -34,9 +34,10 @@ $text_body_headers = $parser->getMessageBodyHeaders('text');
|
||||||
$content_type = idx($text_body_headers, 'content-type');
|
$content_type = idx($text_body_headers, 'content-type');
|
||||||
if (
|
if (
|
||||||
!phutil_is_utf8($text_body) &&
|
!phutil_is_utf8($text_body) &&
|
||||||
preg_match('/charset="(.*?)"/', $content_type, $matches)
|
(preg_match('/charset="(.*?)"/', $content_type, $matches) ||
|
||||||
|
preg_match('/charset=(\S+)/', $content_type, $matches))
|
||||||
) {
|
) {
|
||||||
$text_body = mb_convert_encoding($text_body, "UTF-8", $matches[1]);
|
$text_body = phutil_utf8_convert($text_body, "UTF-8", $matches[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$headers = $parser->getHeaders();
|
$headers = $parser->getHeaders();
|
||||||
|
|
|
@ -318,7 +318,7 @@ final class PhabricatorRepositoryCommitHeraldWorker
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$encoding = $repository->getDetail('encoding', 'utf-8');
|
$encoding = $repository->getDetail('encoding', 'UTF-8');
|
||||||
|
|
||||||
$result = null;
|
$result = null;
|
||||||
$patch_error = null;
|
$patch_error = null;
|
||||||
|
@ -347,9 +347,8 @@ final class PhabricatorRepositoryCommitHeraldWorker
|
||||||
if ($len <= $inline_patches) {
|
if ($len <= $inline_patches) {
|
||||||
// We send email as utf8, so we need to convert the text to utf8 if
|
// We send email as utf8, so we need to convert the text to utf8 if
|
||||||
// we can.
|
// we can.
|
||||||
if (strtolower($encoding) != 'utf-8' &&
|
if ($encoding) {
|
||||||
function_exists('mb_convert_encoding')) {
|
$raw_patch = phutil_utf8_convert($raw_patch, 'UTF-8', $encoding);
|
||||||
$raw_patch = mb_convert_encoding($raw_patch, 'utf-8', $encoding);
|
|
||||||
}
|
}
|
||||||
$result = phutil_utf8ize($raw_patch);
|
$result = phutil_utf8ize($raw_patch);
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,17 +37,9 @@ final class PhabricatorRepositoryGitCommitMessageParserWorker
|
||||||
$parts = explode("\0", $info);
|
$parts = explode("\0", $info);
|
||||||
$encoding = array_shift($parts);
|
$encoding = array_shift($parts);
|
||||||
|
|
||||||
// See note above - git doesn't always convert the encoding correctly.
|
|
||||||
$do_convert = false;
|
|
||||||
if (strlen($encoding) && strtoupper($encoding) != 'UTF-8') {
|
|
||||||
if (function_exists('mb_convert_encoding')) {
|
|
||||||
$do_convert = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($parts as $key => $part) {
|
foreach ($parts as $key => $part) {
|
||||||
if ($do_convert) {
|
if ($encoding) {
|
||||||
$parts[$key] = mb_convert_encoding($part, 'UTF-8', $encoding);
|
$part = phutil_utf8_convert($part, 'UTF-8', $encoding);
|
||||||
}
|
}
|
||||||
$parts[$key] = phutil_utf8ize($part);
|
$parts[$key] = phutil_utf8ize($part);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue