Skip to content

Commit

Permalink
Merge pull request mozilla#8962 from Snuffleupagus/CMapReaderFactory-…
Browse files Browse the repository at this point in the history
…baseUrl-check

Check that `this.baseUrl` is defined before attempting to fetch any data in `DOMCMapReaderFactory`/`NodeCMapReaderFactory`
  • Loading branch information
yurydelendik authored Sep 29, 2017
2 parents c58b9fe + 7615cbc commit e95c53b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/display/dom_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.'));
}
Expand Down
40 changes: 38 additions & 2 deletions test/unit/cmap_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
Expand Down
4 changes: 4 additions & 0 deletions test/unit/test_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.'));
}
Expand Down

0 comments on commit e95c53b

Please sign in to comment.