diff --git a/apps/dav/lib/CardDAV/ImageExportPlugin.php b/apps/dav/lib/CardDAV/ImageExportPlugin.php index e4b1047173de7..5bcbf80c94c5b 100644 --- a/apps/dav/lib/CardDAV/ImageExportPlugin.php +++ b/apps/dav/lib/CardDAV/ImageExportPlugin.php @@ -15,6 +15,7 @@ use Sabre\HTTP\RequestInterface; use Sabre\HTTP\ResponseInterface; use Symfony\Component\HttpFoundation\HeaderUtils; +use Symfony\Component\String\UnicodeString; class ImageExportPlugin extends ServerPlugin { @@ -88,9 +89,7 @@ public function httpGet(RequestInterface $request, ResponseInterface $response) $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); diff --git a/apps/dav/lib/Provisioning/Apple/AppleProvisioningPlugin.php b/apps/dav/lib/Provisioning/Apple/AppleProvisioningPlugin.php index 8796db84f5836..59a33a31f9e39 100644 --- a/apps/dav/lib/Provisioning/Apple/AppleProvisioningPlugin.php +++ b/apps/dav/lib/Provisioning/Apple/AppleProvisioningPlugin.php @@ -16,6 +16,7 @@ use Sabre\HTTP\RequestInterface; use Sabre\HTTP\ResponseInterface; use Symfony\Component\HttpFoundation\HeaderUtils; +use Symfony\Component\String\UnicodeString; class AppleProvisioningPlugin extends ServerPlugin { /** @@ -129,9 +130,7 @@ public function httpGet(RequestInterface $request, ResponseInterface $response): $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); diff --git a/lib/public/AppFramework/Http/DownloadResponse.php b/lib/public/AppFramework/Http/DownloadResponse.php index 6f3a3660ce11a..f80bc0cc371fc 100644 --- a/lib/public/AppFramework/Http/DownloadResponse.php +++ b/lib/public/AppFramework/Http/DownloadResponse.php @@ -9,6 +9,7 @@ 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 @@ public function __construct(string $filename, string $contentType, int $status = 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); }