Fix UTF double encoding in file editor (#2199)

This commit is contained in:
Lance Pioch
2026-02-14 10:33:35 -05:00
committed by GitHub
parent cf2a26bbf0
commit 44f6cf8928
3 changed files with 7 additions and 3 deletions

View File

@@ -149,7 +149,11 @@ class EditFiles extends Page
try {
$contents = $this->getDaemonFileRepository()->getContent($this->path, config('panel.files.max_edit_size'));
return mb_convert_encoding($contents, 'UTF-8', ['UTF-8', 'UTF-16', 'ISO-8859-1', 'ASCII']);
if (mb_check_encoding($contents, 'UTF-8')) {
return $contents;
}
return mb_convert_encoding($contents, 'UTF-8', 'ISO-8859-1');
} catch (FileSizeTooLargeException) {
AlertBanner::make('file_too_large')
->title(trans('server/file.alerts.file_too_large.title', ['name' => basename($this->path)]))

View File

@@ -77,7 +77,7 @@ class FileController extends ClientApiController
->property('file', $request->get('file'))
->log();
return new Response($response, Response::HTTP_OK, ['Content-Type' => 'text/plain']);
return new Response($response, Response::HTTP_OK, ['Content-Type' => 'text/plain; charset=utf-8']);
}
/**

View File

@@ -53,7 +53,7 @@ class DaemonFileRepository extends DaemonRepository
{
$response = $this->getHttpClient()
->withQueryParameters(['file' => $path])
->withBody($content)
->withBody($content, 'text/plain')
->post("/api/servers/{$this->server->uuid}/files/write");
if ($response->status() === 400) {