Merge pull request #60649 from nextcloud/worktree-fix-content-disposition

fix(http): avoid iconv for header ascii fallback
This commit is contained in:
Christoph Wurst 2026-05-26 09:22:40 +02:00 committed by GitHub
commit 29ebfa7db4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 6 additions and 9 deletions

View file

@ -15,6 +15,7 @@ use Sabre\DAV\ServerPlugin;
use Sabre\HTTP\RequestInterface;
use Sabre\HTTP\ResponseInterface;
use Symfony\Component\HttpFoundation\HeaderUtils;
use Symfony\Component\String\UnicodeString;
class ImageExportPlugin extends ServerPlugin {
@ -89,9 +90,7 @@ class ImageExportPlugin extends ServerPlugin {
$response->setHeader('Content-Type', $file->getMimeType());
$fileName = $node->getName() . '.' . PhotoCache::ALLOWED_CONTENT_TYPES[$file->getMimeType()];
$sanitized = str_replace(['/', '\\'], '-', $fileName);
$fallback = @iconv('UTF-8', 'ASCII//TRANSLIT', $sanitized) ?: $sanitized;
$fallback = preg_replace('/[^\x20-\x7e]/', '', $fallback);
$fallback = str_replace('%', '', $fallback);
$fallback = str_replace('%', '', (new UnicodeString($sanitized))->ascii()->toString());
$response->setHeader('Content-Disposition', HeaderUtils::makeDisposition(HeaderUtils::DISPOSITION_ATTACHMENT, $sanitized, $fallback));
$response->setStatus(Http::STATUS_OK);

View file

@ -18,6 +18,7 @@ use Sabre\DAV\ServerPlugin;
use Sabre\HTTP\RequestInterface;
use Sabre\HTTP\ResponseInterface;
use Symfony\Component\HttpFoundation\HeaderUtils;
use Symfony\Component\String\UnicodeString;
class AppleProvisioningPlugin extends ServerPlugin {
/**
@ -126,9 +127,7 @@ class AppleProvisioningPlugin extends ServerPlugin {
$response->setStatus(Http::STATUS_OK);
$sanitized = str_replace(['/', '\\'], '-', $filename);
$fallback = @iconv('UTF-8', 'ASCII//TRANSLIT', $sanitized) ?: $sanitized;
$fallback = preg_replace('/[^\x20-\x7e]/', '', $fallback);
$fallback = str_replace('%', '', $fallback);
$fallback = str_replace('%', '', (new UnicodeString($sanitized))->ascii()->toString());
$response->setHeader('Content-Disposition', HeaderUtils::makeDisposition(HeaderUtils::DISPOSITION_ATTACHMENT, $sanitized, $fallback));
$response->setHeader('Content-Type', 'application/xml; charset=utf-8');
$response->setBody($body);

View file

@ -9,6 +9,7 @@ namespace OCP\AppFramework\Http;
use OCP\AppFramework\Http;
use Symfony\Component\HttpFoundation\HeaderUtils;
use Symfony\Component\String\UnicodeString;
/**
* Prompts the user to download the a file
@ -31,9 +32,7 @@ class DownloadResponse extends Response {
parent::__construct($status, $headers);
$sanitized = str_replace(['/', '\\'], '-', $filename);
$fallback = @iconv('UTF-8', 'ASCII//TRANSLIT', $sanitized) ?: $sanitized;
$fallback = preg_replace('/[^\x20-\x7e]/', '', $fallback);
$fallback = str_replace('%', '', $fallback);
$fallback = str_replace('%', '', (new UnicodeString($sanitized))->ascii()->toString());
$this->addHeader('Content-Disposition', HeaderUtils::makeDisposition(HeaderUtils::DISPOSITION_ATTACHMENT, $sanitized, $fallback));
$this->addHeader('Content-Type', $contentType);
}