diff --git a/test/unit/ui_utils_spec.js b/test/unit/ui_utils_spec.js index 145b30d6a..1bbb175d6 100644 --- a/test/unit/ui_utils_spec.js +++ b/test/unit/ui_utils_spec.js @@ -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 diff --git a/web/ui_utils.js b/web/ui_utils.js index d7806aa8a..940ca81db 100644 --- a/web/ui_utils.js +++ b/web/ui_utils.js @@ -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.');