Skip to content

Commit 6f39bad

Browse files
Merge pull request #60723 from nextcloud/backport/60649/stable34
[stable34] fix(http): avoid iconv for header ascii fallback
2 parents 533f84f + eb42b72 commit 6f39bad

3 files changed

Lines changed: 6 additions & 9 deletions

File tree

apps/dav/lib/CardDAV/ImageExportPlugin.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Sabre\HTTP\RequestInterface;
1616
use Sabre\HTTP\ResponseInterface;
1717
use Symfony\Component\HttpFoundation\HeaderUtils;
18+
use Symfony\Component\String\UnicodeString;
1819

1920
class ImageExportPlugin extends ServerPlugin {
2021

@@ -89,9 +90,7 @@ public function httpGet(RequestInterface $request, ResponseInterface $response)
8990
$response->setHeader('Content-Type', $file->getMimeType());
9091
$fileName = $node->getName() . '.' . PhotoCache::ALLOWED_CONTENT_TYPES[$file->getMimeType()];
9192
$sanitized = str_replace(['/', '\\'], '-', $fileName);
92-
$fallback = @iconv('UTF-8', 'ASCII//TRANSLIT', $sanitized) ?: $sanitized;
93-
$fallback = preg_replace('/[^\x20-\x7e]/', '', $fallback);
94-
$fallback = str_replace('%', '', $fallback);
93+
$fallback = str_replace('%', '', (new UnicodeString($sanitized))->ascii()->toString());
9594
$response->setHeader('Content-Disposition', HeaderUtils::makeDisposition(HeaderUtils::DISPOSITION_ATTACHMENT, $sanitized, $fallback));
9695
$response->setStatus(Http::STATUS_OK);
9796

apps/dav/lib/Provisioning/Apple/AppleProvisioningPlugin.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Sabre\HTTP\RequestInterface;
1919
use Sabre\HTTP\ResponseInterface;
2020
use Symfony\Component\HttpFoundation\HeaderUtils;
21+
use Symfony\Component\String\UnicodeString;
2122

2223
class AppleProvisioningPlugin extends ServerPlugin {
2324
/**
@@ -126,9 +127,7 @@ public function httpGet(RequestInterface $request, ResponseInterface $response):
126127

127128
$response->setStatus(Http::STATUS_OK);
128129
$sanitized = str_replace(['/', '\\'], '-', $filename);
129-
$fallback = @iconv('UTF-8', 'ASCII//TRANSLIT', $sanitized) ?: $sanitized;
130-
$fallback = preg_replace('/[^\x20-\x7e]/', '', $fallback);
131-
$fallback = str_replace('%', '', $fallback);
130+
$fallback = str_replace('%', '', (new UnicodeString($sanitized))->ascii()->toString());
132131
$response->setHeader('Content-Disposition', HeaderUtils::makeDisposition(HeaderUtils::DISPOSITION_ATTACHMENT, $sanitized, $fallback));
133132
$response->setHeader('Content-Type', 'application/xml; charset=utf-8');
134133
$response->setBody($body);

lib/public/AppFramework/Http/DownloadResponse.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use OCP\AppFramework\Http;
1111
use Symfony\Component\HttpFoundation\HeaderUtils;
12+
use Symfony\Component\String\UnicodeString;
1213

1314
/**
1415
* Prompts the user to download the a file
@@ -31,9 +32,7 @@ public function __construct(string $filename, string $contentType, int $status =
3132
parent::__construct($status, $headers);
3233

3334
$sanitized = str_replace(['/', '\\'], '-', $filename);
34-
$fallback = @iconv('UTF-8', 'ASCII//TRANSLIT', $sanitized) ?: $sanitized;
35-
$fallback = preg_replace('/[^\x20-\x7e]/', '', $fallback);
36-
$fallback = str_replace('%', '', $fallback);
35+
$fallback = str_replace('%', '', (new UnicodeString($sanitized))->ascii()->toString());
3736
$this->addHeader('Content-Disposition', HeaderUtils::makeDisposition(HeaderUtils::DISPOSITION_ATTACHMENT, $sanitized, $fallback));
3837
$this->addHeader('Content-Type', $contentType);
3938
}

0 commit comments

Comments
 (0)