Merge pull request #8962 from Snuffleupagus/CMapReaderFactory-baseUrl-check
Check that `this.baseUrl` is defined before attempting to fetch any data in `DOMCMapReaderFactory`/`NodeCMapReaderFactory`
This commit is contained in:
commit
f206ee56bf
@ -68,6 +68,10 @@ class DOMCMapReaderFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fetch({ name, }) {
|
fetch({ name, }) {
|
||||||
|
if (!this.baseUrl) {
|
||||||
|
return Promise.reject(new Error('CMap baseUrl must be specified, ' +
|
||||||
|
'see "PDFJS.cMapUrl" (and also "PDFJS.cMapPacked").'));
|
||||||
|
}
|
||||||
if (!name) {
|
if (!name) {
|
||||||
return Promise.reject(new Error('CMap name must be specified.'));
|
return Promise.reject(new Error('CMap name must be specified.'));
|
||||||
}
|
}
|
||||||
|
@ -281,8 +281,44 @@ describe('cmap', function() {
|
|||||||
done.fail('No CMap should be loaded');
|
done.fail('No CMap should be loaded');
|
||||||
}, function (reason) {
|
}, function (reason) {
|
||||||
expect(reason instanceof Error).toEqual(true);
|
expect(reason instanceof Error).toEqual(true);
|
||||||
expect(reason.message).toEqual(
|
expect(reason.message).toEqual('CMap baseUrl must be specified, ' +
|
||||||
'Unable to load CMap at: nullAdobe-Japan1-1');
|
'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();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -51,6 +51,10 @@ class NodeCMapReaderFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fetch({ name, }) {
|
fetch({ name, }) {
|
||||||
|
if (!this.baseUrl) {
|
||||||
|
return Promise.reject(new Error('CMap baseUrl must be specified, ' +
|
||||||
|
'see "PDFJS.cMapUrl" (and also "PDFJS.cMapPacked").'));
|
||||||
|
}
|
||||||
if (!name) {
|
if (!name) {
|
||||||
return Promise.reject(new Error('CMap name must be specified.'));
|
return Promise.reject(new Error('CMap name must be specified.'));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user