Merge pull request #8432 from Snuffleupagus/rm-nameddest-fallback

Remove the special handling for `nameddest`s that look like standard pageNumbers
This commit is contained in:
Brendan Dahl 2017-05-22 11:38:10 -07:00 committed by GitHub
commit 5df0cccaa3
4 changed files with 13 additions and 27 deletions

View File

@ -683,13 +683,9 @@ var Catalog = (function CatalogClosure() {
remoteDest = remoteDest.name; remoteDest = remoteDest.name;
} }
if (isString(url)) { if (isString(url)) {
var baseUrl = url.split('#')[0]; let baseUrl = url.split('#')[0];
if (isString(remoteDest)) { if (isString(remoteDest)) {
// In practice, a named destination may contain only a number. url = baseUrl + '#' + remoteDest;
// If that happens, use the '#nameddest=' form to avoid the link
// redirecting to a page, instead of the correct destination.
url = baseUrl + '#' +
(/^\d+$/.test(remoteDest) ? 'nameddest=' : '') + remoteDest;
} else if (isArray(remoteDest)) { } else if (isArray(remoteDest)) {
url = baseUrl + '#' + JSON.stringify(remoteDest); url = baseUrl + '#' + JSON.stringify(remoteDest);
} }

View File

@ -503,9 +503,8 @@ describe('annotation', function() {
var data = annotation.data; var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.LINK); expect(data.annotationType).toEqual(AnnotationType.LINK);
expect(data.url).toEqual('http://www.example.com/test.pdf#nameddest=15'); expect(data.url).toEqual('http://www.example.com/test.pdf#15');
expect(data.unsafeUrl).toEqual( expect(data.unsafeUrl).toEqual('http://www.example.com/test.pdf#15');
'http://www.example.com/test.pdf#nameddest=15');
expect(data.dest).toBeUndefined(); expect(data.dest).toBeUndefined();
expect(data.newWindow).toBeFalsy(); expect(data.newWindow).toBeFalsy();
}); });

View File

@ -944,16 +944,16 @@ describe('api', function() {
expect(defaultAnnotations[0].url).toBeUndefined(); expect(defaultAnnotations[0].url).toBeUndefined();
expect(defaultAnnotations[0].unsafeUrl).toEqual( expect(defaultAnnotations[0].unsafeUrl).toEqual(
'../../0021/002156/215675E.pdf#nameddest=15'); '../../0021/002156/215675E.pdf#15');
expect(docBaseUrlAnnotations[0].url).toEqual( expect(docBaseUrlAnnotations[0].url).toEqual(
'http://www.example.com/0021/002156/215675E.pdf#nameddest=15'); 'http://www.example.com/0021/002156/215675E.pdf#15');
expect(docBaseUrlAnnotations[0].unsafeUrl).toEqual( expect(docBaseUrlAnnotations[0].unsafeUrl).toEqual(
'../../0021/002156/215675E.pdf#nameddest=15'); '../../0021/002156/215675E.pdf#15');
expect(invalidDocBaseUrlAnnotations[0].url).toBeUndefined(); expect(invalidDocBaseUrlAnnotations[0].url).toBeUndefined();
expect(invalidDocBaseUrlAnnotations[0].unsafeUrl).toEqual( expect(invalidDocBaseUrlAnnotations[0].unsafeUrl).toEqual(
'../../0021/002156/215675E.pdf#nameddest=15'); '../../0021/002156/215675E.pdf#15');
Promise.all([ Promise.all([
defaultLoadingTask.destroy(), defaultLoadingTask.destroy(),

View File

@ -16,11 +16,6 @@
import { getGlobalEventBus } from './dom_events'; import { getGlobalEventBus } from './dom_events';
import { parseQueryString } from './ui_utils'; import { parseQueryString } from './ui_utils';
var PageNumberRegExp = /^\d+$/;
function isPageNumber(str) {
return PageNumberRegExp.test(str);
}
/** /**
* @typedef {Object} PDFLinkServiceOptions * @typedef {Object} PDFLinkServiceOptions
* @property {EventBus} eventBus - The application event bus. * @property {EventBus} eventBus - The application event bus.
@ -154,19 +149,15 @@ var PDFLinkService = (function PDFLinkServiceClosure() {
}, },
/** /**
* @param dest - The PDF destination object. * @param {string|Array} dest - The PDF destination object.
* @returns {string} The hyperlink to the PDF object. * @returns {string} The hyperlink to the PDF object.
*/ */
getDestinationHash: function PDFLinkService_getDestinationHash(dest) { getDestinationHash(dest) {
if (typeof dest === 'string') { if (typeof dest === 'string') {
// In practice, a named destination may contain only a number. return this.getAnchorUrl('#' + escape(dest));
// If that happens, use the '#nameddest=' form to avoid the link
// redirecting to a page, instead of the correct destination.
return this.getAnchorUrl(
'#' + (isPageNumber(dest) ? 'nameddest=' : '') + escape(dest));
} }
if (dest instanceof Array) { if (dest instanceof Array) {
var str = JSON.stringify(dest); let str = JSON.stringify(dest);
return this.getAnchorUrl('#' + escape(str)); return this.getAnchorUrl('#' + escape(str));
} }
return this.getAnchorUrl(''); return this.getAnchorUrl('');
@ -259,7 +250,7 @@ var PDFLinkService = (function PDFLinkServiceClosure() {
} }
} else { // Named (or explicit) destination. } else { // Named (or explicit) destination.
if ((typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) && if ((typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) &&
isPageNumber(hash) && hash <= this.pagesCount) { /^\d+$/.test(hash) && hash <= this.pagesCount) {
console.warn('PDFLinkService_setHash: specifying a page number ' + console.warn('PDFLinkService_setHash: specifying a page number ' +
'directly after the hash symbol (#) is deprecated, ' + 'directly after the hash symbol (#) is deprecated, ' +
'please use the "#page=' + hash + '" form instead.'); 'please use the "#page=' + hash + '" form instead.');