Skip to content

Commit 5c0c52c

Browse files
Merge pull request #60722 from nextcloud/backport/60649/stable33
[stable33] fix(http): avoid iconv for header ascii fallback
2 parents 62c72ff + d86f13e commit 5c0c52c

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

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

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

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

2021
class AppleProvisioningPlugin extends ServerPlugin {
2122
/**
@@ -129,9 +130,7 @@ public function httpGet(RequestInterface $request, ResponseInterface $response):
129130

130131
$response->setStatus(Http::STATUS_OK);
131132
$sanitized = str_replace(['/', '\\'], '-', $filename);
132-
$fallback = @iconv('UTF-8', 'ASCII//TRANSLIT', $sanitized) ?: $sanitized;
133-
$fallback = preg_replace('/[^\x20-\x7e]/', '', $fallback);
134-
$fallback = str_replace('%', '', $fallback);
133+
$fallback = str_replace('%', '', (new UnicodeString($sanitized))->ascii()->toString());
135134
$response->setHeader('Content-Disposition', HeaderUtils::makeDisposition(HeaderUtils::DISPOSITION_ATTACHMENT, $sanitized, $fallback));
136135
$response->setHeader('Content-Type', 'application/xml; charset=utf-8');
137136
$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)