Prevent getPDFFileNameFromURL
from breaking if the url
parameter is not a string
This commit is contained in:
parent
6da78bcc3f
commit
1c814e208e
@ -80,6 +80,12 @@ describe('ui_utils', function() {
|
||||
expect(getPDFFileNameFromURL('/pdfs/file3.txt', '')).toEqual('');
|
||||
});
|
||||
|
||||
it('gets fallback filename when url is not a string', function() {
|
||||
expect(getPDFFileNameFromURL(null)).toEqual('document.pdf');
|
||||
|
||||
expect(getPDFFileNameFromURL(null, 'file.pdf')).toEqual('file.pdf');
|
||||
});
|
||||
|
||||
it('gets PDF filename from URL containing leading/trailing whitespace',
|
||||
function() {
|
||||
// Relative URL
|
||||
|
@ -548,6 +548,9 @@ function isDataSchema(url) {
|
||||
* @returns {string} Guessed PDF filename.
|
||||
*/
|
||||
function getPDFFileNameFromURL(url, defaultFilename = 'document.pdf') {
|
||||
if (typeof url !== 'string') {
|
||||
return defaultFilename;
|
||||
}
|
||||
if (isDataSchema(url)) {
|
||||
console.warn('getPDFFileNameFromURL: ' +
|
||||
'ignoring "data:" URL for performance reasons.');
|
||||
|
Loading…
Reference in New Issue
Block a user