Merge pull request #7750 from Snuffleupagus/PDFLinkService_navigateTo-more-validation
Add more validation to `PDFLinkService_navigateTo`
This commit is contained in:
commit
abc417cee9
@ -299,7 +299,7 @@ var LinkAnnotationElement = (function LinkAnnotationElementClosure() {
|
|||||||
if (this.data.action) {
|
if (this.data.action) {
|
||||||
this._bindNamedAction(link, this.data.action);
|
this._bindNamedAction(link, this.data.action);
|
||||||
} else {
|
} else {
|
||||||
this._bindLink(link, (this.data.dest || null));
|
this._bindLink(link, this.data.dest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,13 +106,21 @@ var PDFLinkService = (function PDFLinkServiceClosure() {
|
|||||||
|
|
||||||
var goToDestination = function(destRef) {
|
var goToDestination = function(destRef) {
|
||||||
// dest array looks like that: <page-ref> </XYZ|/FitXXX> <args..>
|
// dest array looks like that: <page-ref> </XYZ|/FitXXX> <args..>
|
||||||
var pageNumber = destRef instanceof Object ?
|
var pageNumber;
|
||||||
self._pagesRefCache[destRef.num + ' ' + destRef.gen + ' R'] :
|
if (destRef instanceof Object) {
|
||||||
(destRef + 1);
|
pageNumber = self._cachedPageNumber(destRef);
|
||||||
|
} else if ((destRef | 0) === destRef) { // Integer
|
||||||
|
pageNumber = destRef + 1;
|
||||||
|
} else {
|
||||||
|
console.error('PDFLinkService_navigateTo: "' + destRef +
|
||||||
|
'" is not a valid destination reference.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (pageNumber) {
|
if (pageNumber) {
|
||||||
if (pageNumber > self.pagesCount) {
|
if (pageNumber < 1 || pageNumber > self.pagesCount) {
|
||||||
console.error('PDFLinkService_navigateTo: ' +
|
console.error('PDFLinkService_navigateTo: "' + pageNumber +
|
||||||
'Trying to navigate to a non-existent page.');
|
'" is a non-existent page number.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
self.pdfViewer.scrollPageIntoView({
|
self.pdfViewer.scrollPageIntoView({
|
||||||
@ -130,10 +138,12 @@ var PDFLinkService = (function PDFLinkServiceClosure() {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
self.pdfDocument.getPageIndex(destRef).then(function (pageIndex) {
|
self.pdfDocument.getPageIndex(destRef).then(function (pageIndex) {
|
||||||
var pageNum = pageIndex + 1;
|
self.cachePageRef(pageIndex + 1, destRef);
|
||||||
var cacheKey = destRef.num + ' ' + destRef.gen + ' R';
|
|
||||||
self._pagesRefCache[cacheKey] = pageNum;
|
|
||||||
goToDestination(destRef);
|
goToDestination(destRef);
|
||||||
|
}).catch(function () {
|
||||||
|
console.error('PDFLinkService_navigateTo: "' + destRef +
|
||||||
|
'" is not a valid page reference.');
|
||||||
|
return;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -148,7 +158,9 @@ var PDFLinkService = (function PDFLinkServiceClosure() {
|
|||||||
destinationPromise.then(function(destination) {
|
destinationPromise.then(function(destination) {
|
||||||
dest = destination;
|
dest = destination;
|
||||||
if (!(destination instanceof Array)) {
|
if (!(destination instanceof Array)) {
|
||||||
return; // invalid destination
|
console.error('PDFLinkService_navigateTo: "' + destination +
|
||||||
|
'" is not a valid destination array.');
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
goToDestination(destination[0]);
|
goToDestination(destination[0]);
|
||||||
});
|
});
|
||||||
@ -339,7 +351,12 @@ var PDFLinkService = (function PDFLinkServiceClosure() {
|
|||||||
cachePageRef: function PDFLinkService_cachePageRef(pageNum, pageRef) {
|
cachePageRef: function PDFLinkService_cachePageRef(pageNum, pageRef) {
|
||||||
var refStr = pageRef.num + ' ' + pageRef.gen + ' R';
|
var refStr = pageRef.num + ' ' + pageRef.gen + ' R';
|
||||||
this._pagesRefCache[refStr] = pageNum;
|
this._pagesRefCache[refStr] = pageNum;
|
||||||
}
|
},
|
||||||
|
|
||||||
|
_cachedPageNumber: function PDFLinkService_cachedPageNumber(pageRef) {
|
||||||
|
var refStr = pageRef.num + ' ' + pageRef.gen + ' R';
|
||||||
|
return (this._pagesRefCache && this._pagesRefCache[refStr]) || null;
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
function isValidExplicitDestination(dest) {
|
function isValidExplicitDestination(dest) {
|
||||||
|
@ -90,10 +90,13 @@ var PDFOutlineViewer = (function PDFOutlineViewerClosure() {
|
|||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var linkService = this.linkService;
|
var self = this, destination = item.dest;
|
||||||
element.href = linkService.getDestinationHash(item.dest);
|
|
||||||
element.onclick = function goToDestination(e) {
|
element.href = self.linkService.getDestinationHash(destination);
|
||||||
linkService.navigateTo(item.dest);
|
element.onclick = function () {
|
||||||
|
if (destination) {
|
||||||
|
self.linkService.navigateTo(destination);
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user