fix(http): avoid iconv for header ascii fallback

iconv transliteration is locale- and config-dependent and fails silently
on some setups. UnicodeString::ascii() from symfony/string uses a built-in
transliteration table backed by symfony/polyfill-intl-normalizer, so it
works on all setups without requiring optional PHP extensions.

Assisted-by: Claude:claude-sonnet-4-6
Signed-off-by: Christoph Wurst <1374172+ChristophWurst@users.noreply.github.com>
This commit is contained in:
Christoph Wurst 2026-05-21 21:17:21 +02:00
parent cbc8033a44
commit d1d24e65a4
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);
}