Skip to content

Commit

Permalink
Support filename downloads with special characters (#4097)
Browse files Browse the repository at this point in the history
* Support filename downloads with special characters  (related to #3865 and #3867)

* Use spaces

Co-authored-by: Rico Suter <[email protected]>
  • Loading branch information
knoepdan and RicoSuter authored Aug 15, 2022
1 parent 3d6b66c commit 6a4cc21
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@ const contentDisposition = response.headers ? response.headers["content-disposit
{% else -%}
const contentDisposition = response.headers ? response.headers.get("content-disposition") : undefined;
{% endif -%}
const fileNameMatch = contentDisposition ? /filename="?([^"]*?)"?(;|$)/g.exec(contentDisposition) : undefined;
const fileName = fileNameMatch && fileNameMatch.length > 1 ? fileNameMatch[1] : undefined;
let fileNameMatch = contentDisposition ? /filename\*=(?:(\\?['"])(.*?)\1|(?:[^\s]+'.*?')?([^;\n]*))/g.exec(contentDisposition) : undefined;
let fileName = fileNameMatch && fileNameMatch.length > 1 ? fileNameMatch[3] || fileNameMatch[2] : undefined;
if (fileName) {
fileName = decodeURIComponent(fileName);
} else {
fileNameMatch = contentDisposition ? /filename="?([^"]*?)"?(;|$)/g.exec(contentDisposition) : undefined;
fileName = fileNameMatch && fileNameMatch.length > 1 ? fileNameMatch[1] : undefined;
}
{% if operation.WrapResponse -%}
{% if Framework.IsAngular -%}
return {{ Framework.RxJs.ObservableOfMethod }}(new {{ operation.ResponseClass }}(status, _headers, { fileName: fileName, data: {% if Framework.Angular.UseHttpClient %}responseBlob as any{% else %}response.blob() as any{% endif %}, status: status, headers: _headers }));
Expand Down

0 comments on commit 6a4cc21

Please sign in to comment.