1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-20 15:18:08 +02:00

Fix a PDFHistory regression with document hashes of the nameddest=... form

Unfortunately I've just found out that this isn't working entirely correct; my apologies for accidentally breaking this in PR 8775.

Compare e.g. this link: http://mirrors.ctan.org/info/lshort/english/lshort.pdf#page.157, with this one: http://mirrors.ctan.org/info/lshort/english/lshort.pdf#nameddest=page.157.

Notice how in the *second* case, the history stops working correctly.

*The various edge-case regressions in the new `PDFHistory` code is reminding my why I put off the rewrite for so long :-(*
This commit is contained in:
Jonas Jenwald 2017-10-09 18:00:26 +02:00
parent c80237729c
commit 33b1d1b20a
2 changed files with 55 additions and 14 deletions

View file

@ -177,8 +177,8 @@ class PDFHistory {
let forceReplace = false;
if (this._destination &&
(this._destination.hash === hash ||
isDestsEqual(this._destination.dest, explicitDest))) {
(isDestHashesEqual(this._destination.hash, hash) ||
isDestArraysEqual(this._destination.dest, explicitDest))) {
// When the new destination is identical to `this._destination`, and
// its `page` is undefined, replace the current browser history entry.
// NOTE: This can only occur if `this._destination` was set either:
@ -555,7 +555,21 @@ class PDFHistory {
}
}
function isDestsEqual(firstDest, secondDest) {
function isDestHashesEqual(destHash, pushHash) {
if (typeof destHash !== 'string' || typeof pushHash !== 'string') {
return false;
}
if (destHash === pushHash) {
return true;
}
let { nameddest, } = parseQueryString(destHash);
if (nameddest === pushHash) {
return true;
}
return false;
}
function isDestArraysEqual(firstDest, secondDest) {
function isEntryEqual(first, second) {
if (typeof first !== typeof second) {
return false;
@ -593,5 +607,6 @@ function isDestsEqual(firstDest, secondDest) {
export {
PDFHistory,
isDestsEqual,
isDestHashesEqual,
isDestArraysEqual,
};