decode filename when match an urlencode filename from contentDispositionFilename
This commit is contained in:
parent
323b2eabcf
commit
c61205d980
@ -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;
|
||||
}
|
||||
|
@ -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() {
|
||||
|
Loading…
Reference in New Issue
Block a user