From c61205d9801ef4a7687324ebf49a8bc09919ee96 Mon Sep 17 00:00:00 2001 From: wangsongyan <1104237534@qq.com> Date: Tue, 30 Jul 2019 11:37:10 +0800 Subject: [PATCH] decode filename when match an urlencode filename from contentDispositionFilename --- src/display/network_utils.js | 5 +++++ test/unit/network_utils_spec.js | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/display/network_utils.js b/src/display/network_utils.js index ae9632d88..911a191c6 100644 --- a/src/display/network_utils.js +++ b/src/display/network_utils.js @@ -61,6 +61,11 @@ function extractFilenameFromHeader(getResponseHeader) { const contentDisposition = getResponseHeader('Content-Disposition'); if (contentDisposition) { let filename = getFilenameFromContentDispositionHeader(contentDisposition); + if (filename.includes('%')) { + try { + filename = decodeURIComponent(filename); + } catch (ex) {} + } if (/\.pdf$/i.test(filename)) { return filename; } diff --git a/test/unit/network_utils_spec.js b/test/unit/network_utils_spec.js index 16cf6544e..e7b14c41a 100644 --- a/test/unit/network_utils_spec.js +++ b/test/unit/network_utils_spec.js @@ -238,6 +238,20 @@ describe('network_utils', function() { } throw new Error(`Unexpected headerName: ${headerName}`); })).toEqual('filename.pdf'); + + expect(extractFilenameFromHeader((headerName) => { + if (headerName === 'Content-Disposition') { + return 'attachment; filename="%e4%b8%ad%e6%96%87.pdf"'; + } + throw new Error(`Unexpected headerName: ${headerName}`); + })).toEqual('中文.pdf'); + + expect(extractFilenameFromHeader((headerName) => { + if (headerName === 'Content-Disposition') { + return 'attachment; filename="100%.pdf"'; + } + throw new Error(`Unexpected headerName: ${headerName}`); + })).toEqual('100%.pdf'); }); it('gets the filename from the response header (RFC 6266)', function() {