diff --git a/src/display/dom_utils.js b/src/display/dom_utils.js index 21cfb0425..592765564 100644 --- a/src/display/dom_utils.js +++ b/src/display/dom_utils.js @@ -68,6 +68,10 @@ class DOMCMapReaderFactory { } fetch({ name, }) { + if (!this.baseUrl) { + return Promise.reject(new Error('CMap baseUrl must be specified, ' + + 'see "PDFJS.cMapUrl" (and also "PDFJS.cMapPacked").')); + } if (!name) { return Promise.reject(new Error('CMap name must be specified.')); } diff --git a/test/unit/cmap_spec.js b/test/unit/cmap_spec.js index 9a0d03649..457d146eb 100644 --- a/test/unit/cmap_spec.js +++ b/test/unit/cmap_spec.js @@ -281,8 +281,44 @@ describe('cmap', function() { done.fail('No CMap should be loaded'); }, function (reason) { expect(reason instanceof Error).toEqual(true); - expect(reason.message).toEqual( - 'Unable to load CMap at: nullAdobe-Japan1-1'); + expect(reason.message).toEqual('CMap baseUrl must be specified, ' + + 'see "PDFJS.cMapUrl" (and also "PDFJS.cMapPacked").'); + done(); + }); + }); + + it('attempts to load a built-in CMap with inconsistent API parameters', + function(done) { + function tmpFetchBuiltInCMap(name) { + let CMapReaderFactory; + if (isNodeJS()) { + CMapReaderFactory = new NodeCMapReaderFactory({ + baseUrl: cMapUrl.node, + isCompressed: false, + }); + } else { + CMapReaderFactory = new DOMCMapReaderFactory({ + baseUrl: cMapUrl.dom, + isCompressed: false, + }); + } + return CMapReaderFactory.fetch({ + name, + }); + } + + let cmapPromise = CMapFactory.create({ + encoding: Name.get('Adobe-Japan1-1'), + fetchBuiltInCMap: tmpFetchBuiltInCMap, + useCMap: null, + }); + cmapPromise.then(function () { + done.fail('No CMap should be loaded'); + }, function (reason) { + expect(reason instanceof Error).toEqual(true); + let message = reason.message; + expect(message.startsWith('Unable to load CMap at: ')).toEqual(true); + expect(message.endsWith('/external/bcmaps/Adobe-Japan1-1')).toEqual(true); done(); }); }); diff --git a/test/unit/test_utils.js b/test/unit/test_utils.js index 27d098dfd..205c7c3a6 100644 --- a/test/unit/test_utils.js +++ b/test/unit/test_utils.js @@ -51,6 +51,10 @@ class NodeCMapReaderFactory { } fetch({ name, }) { + if (!this.baseUrl) { + return Promise.reject(new Error('CMap baseUrl must be specified, ' + + 'see "PDFJS.cMapUrl" (and also "PDFJS.cMapPacked").')); + } if (!name) { return Promise.reject(new Error('CMap name must be specified.')); }