diff --git a/test/unit/ui_utils_spec.js b/test/unit/ui_utils_spec.js index 145b30d6aea09..1bbb175d6f4ce 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/app.js b/web/app.js index 1cc90cdb7adff..3ff363ba1b6b6 100644 --- a/web/app.js +++ b/web/app.js @@ -595,8 +595,8 @@ let PDFViewerApplication = { this.pdfThumbnailViewer.setDocument(null); this.pdfViewer.setDocument(null); - this.pdfLinkService.setDocument(null, null); - this.pdfDocumentProperties.setDocument(null, null); + this.pdfLinkService.setDocument(null); + this.pdfDocumentProperties.setDocument(null); } this.store = null; this.isInitialViewSet = false; diff --git a/web/pdf_document_properties.js b/web/pdf_document_properties.js index 25711af5d2477..329c8dddc25e5 100644 --- a/web/pdf_document_properties.js +++ b/web/pdf_document_properties.js @@ -120,7 +120,7 @@ class PDFDocumentProperties { return Promise.all([ info, metadata, - contentDispositionFilename || getPDFFileNameFromURL(this.url), + contentDispositionFilename || getPDFFileNameFromURL(this.url || ''), this._parseFileSize(this.maybeFileSize), this._parseDate(info.CreationDate), this._parseDate(info.ModDate), @@ -187,7 +187,7 @@ class PDFDocumentProperties { * @param {Object} pdfDocument - A reference to the PDF document. * @param {string} url - The URL of the document. */ - setDocument(pdfDocument, url) { + setDocument(pdfDocument, url = null) { if (this.pdfDocument) { this._reset(); this._updateUI(true); diff --git a/web/pdf_link_service.js b/web/pdf_link_service.js index 3f6af1a724f7d..a0130db7e4143 100644 --- a/web/pdf_link_service.js +++ b/web/pdf_link_service.js @@ -49,7 +49,7 @@ class PDFLinkService { this._pagesRefCache = null; } - setDocument(pdfDocument, baseUrl) { + setDocument(pdfDocument, baseUrl = null) { this.baseUrl = baseUrl; this.pdfDocument = pdfDocument; this._pagesRefCache = Object.create(null); diff --git a/web/ui_utils.js b/web/ui_utils.js index d7806aa8af8b1..940ca81db25a6 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.');