mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-20 23:28:06 +02:00
[api-minor] Let Catalog_getPageIndex
check that the Ref
actually points to a /Page dictionary
Currently the `getPageIndex` method will happily return `0`, even if the `Ref` parameter doesn't actually point to a proper /Page dictionary. Having the API trust that the consumer is doing the right thing seems error-prone, hence this patch which adds a check for this case. Given that the `Catalog_getPageIndex` method isn't used in any hot part of the codebase, this extra check shouldn't be a problem. (Note: in the standard viewer, it is only ever used from `PDFLinkService_navigateTo` if a destination needs to be resolved during document loading, which isn't common enough to be an issue IMHO.)
This commit is contained in:
parent
db46829ef7
commit
01ab15a6f1
5 changed files with 46 additions and 5 deletions
|
@ -360,6 +360,16 @@ describe('api', function() {
|
|||
done.fail(reason);
|
||||
});
|
||||
});
|
||||
it('gets invalid page index', function (done) {
|
||||
var ref = { num: 3, gen: 0 }; // Reference to a font dictionary.
|
||||
var promise = doc.getPageIndex(ref);
|
||||
promise.then(function () {
|
||||
done.fail('shall fail for invalid page reference.');
|
||||
}, function (data) {
|
||||
expect(data instanceof Error).toEqual(true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('gets destinations, from /Dests dictionary', function(done) {
|
||||
var promise = doc.getDestinations();
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* globals expect, it, describe, beforeEach, Name, Dict, Ref, RefSet, Cmd,
|
||||
jasmine, isDict */
|
||||
jasmine, isDict, isRefsEqual */
|
||||
|
||||
'use strict';
|
||||
|
||||
|
@ -158,4 +158,18 @@ describe('primitives', function() {
|
|||
expect(isDict(dict, 'Page')).toEqual(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isRefsEqual', function () {
|
||||
it('should handle different Refs pointing to the same object', function () {
|
||||
var ref1 = new Ref(1, 0);
|
||||
var ref2 = new Ref(1, 0);
|
||||
expect(isRefsEqual(ref1, ref2)).toEqual(true);
|
||||
});
|
||||
|
||||
it('should handle Refs pointing to different objects', function () {
|
||||
var ref1 = new Ref(1, 0);
|
||||
var ref2 = new Ref(2, 0);
|
||||
expect(isRefsEqual(ref1, ref2)).toEqual(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue