-
Notifications
You must be signed in to change notification settings - Fork 10.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change getPDFFileNameFromURL
to ignore data:
URLs for performance reasons (issue 8263)
#8321
Conversation
…nce the `URL` polyfill have made them redundant Also, this changes `createBlob` to throw when `Blob` isn't supported.
getPDFFileNameFromURL
to ignore data:
URLs for performance… … reasons (issue 8263)getPDFFileNameFromURL
to ignore data:
URLs for performance reasons (issue 8263)
/botio unittest |
From: Bot.io (Linux)ReceivedCommand cmd_unittest from @Snuffleupagus received. Current queue size: 0 Live output at: http://107.21.233.14:8877/796b50f18362b4d/output.txt |
From: Bot.io (Windows)ReceivedCommand cmd_unittest from @Snuffleupagus received. Current queue size: 0 Live output at: http://54.215.176.217:8877/b4df5fd0700655b/output.txt |
From: Bot.io (Linux)SuccessFull output at http://107.21.233.14:8877/796b50f18362b4d/output.txt Total script time: 3.04 mins
|
From: Bot.io (Windows)SuccessFull output at http://54.215.176.217:8877/b4df5fd0700655b/output.txt Total script time: 6.55 mins
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good with the change below
web/ui_utils.js
Outdated
if (typeof defaultFilename === 'undefined') { | ||
defaultFilename = 'document.pdf'; | ||
function getPDFFileNameFromURL(url, defaultFilename = 'document.pdf') { | ||
if (url.indexOf('data:') === 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per https://tools.ietf.org/html/rfc3986#section-3.1 , schemes are case-insensitive. I recommend to create the isDataSchema(url) function above and also skip allowed whitespaces, something like:
var i = 0; while (i < url.length && url[i].trim() == '') i++;
return url.substr(i, 5).toLowerCase() === 'data:';
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the review!
I've made the requested changes, and also added a few unit-tests for the whitespace case.
… reasons (issue 8263) The patch also changes the `defaultFilename` to use the ES6 default parameter notation, and fixes the formatting of the JSDoc comment. Finally, since `getPDFFileNameFromURL` currently has no unit-tests, a few basic ones are added to avoid regressions.
…er, instead of downloading them, when `PDFJS.disableCreateObjectURL = false` This prevents issues with the filename detection being skipped, when trying to download the opened PDF attachment, since `getPDFFileNameFromURL` ignores `data:` URLs for performance reasons.
/botio unittest |
From: Bot.io (Linux)ReceivedCommand cmd_unittest from @Snuffleupagus received. Current queue size: 0 Live output at: http://107.21.233.14:8877/458d3baa21701a5/output.txt |
From: Bot.io (Windows)ReceivedCommand cmd_unittest from @Snuffleupagus received. Current queue size: 0 Live output at: http://54.215.176.217:8877/f9ccb988b4e6a21/output.txt |
From: Bot.io (Linux)SuccessFull output at http://107.21.233.14:8877/458d3baa21701a5/output.txt Total script time: 2.98 mins
|
From: Bot.io (Windows)SuccessFull output at http://54.215.176.217:8877/f9ccb988b4e6a21/output.txt Total script time: 6.62 mins
|
Change `getPDFFileNameFromURL` to ignore `data:` URLs for performance reasons (issue 8263)
Please refer to the individual commit messages.
Tentatively fixes #8263.