Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update BaseViewer.scrollPageIntoView to always validate the pageNumber parameter #10245

Merged
merged 2 commits into from
Nov 9, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 24 additions & 26 deletions web/base_viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -660,25 +660,23 @@ class BaseViewer {
* Scrolls page into view.
* @param {ScrollPageIntoViewParameters} params
*/
scrollPageIntoView(params) {
scrollPageIntoView({ pageNumber, destArray = null,
allowNegativeOffset = false, }) {
if (!this.pdfDocument) {
return;
}
let pageNumber = params.pageNumber || 0;
let dest = params.destArray || null;
let allowNegativeOffset = params.allowNegativeOffset || false;

if (this.isInPresentationMode || !dest) {
this._setCurrentPageNumber(pageNumber, /* resetCurrentPageView = */ true);
return;
}

let pageView = this._pages[pageNumber - 1];
const pageView = (Number.isInteger(pageNumber) &&
this._pages[pageNumber - 1]);
if (!pageView) {
console.error(
`${this._name}.scrollPageIntoView: Invalid "pageNumber" parameter.`);
return;
}

if (this.isInPresentationMode || !destArray) {
this._setCurrentPageNumber(pageNumber, /* resetCurrentPageView = */ true);
return;
}
let x = 0, y = 0;
let width = 0, height = 0, widthScale, heightScale;
let changeOrientation = (pageView.rotation % 180 === 0 ? false : true);
Expand All @@ -687,11 +685,11 @@ class BaseViewer {
let pageHeight = (changeOrientation ? pageView.width : pageView.height) /
pageView.scale / CSS_UNITS;
let scale = 0;
switch (dest[1].name) {
switch (destArray[1].name) {
case 'XYZ':
x = dest[2];
y = dest[3];
scale = dest[4];
x = destArray[2];
y = destArray[3];
scale = destArray[4];
// If x and/or y coordinates are not supplied, default to
// _top_ left of the page (not the obvious bottom left,
// since aligning the bottom of the intended page with the
Expand All @@ -705,7 +703,7 @@ class BaseViewer {
break;
case 'FitH':
case 'FitBH':
y = dest[2];
y = destArray[2];
scale = 'page-width';
// According to the PDF spec, section 12.3.2.2, a `null` value in the
// parameter should maintain the position relative to the new page.
Expand All @@ -716,16 +714,16 @@ class BaseViewer {
break;
case 'FitV':
case 'FitBV':
x = dest[2];
x = destArray[2];
width = pageWidth;
height = pageHeight;
scale = 'page-height';
break;
case 'FitR':
x = dest[2];
y = dest[3];
width = dest[4] - x;
height = dest[5] - y;
x = destArray[2];
y = destArray[3];
width = destArray[4] - x;
height = destArray[5] - y;
let hPadding = this.removePageBorders ? 0 : SCROLLBAR_PADDING;
let vPadding = this.removePageBorders ? 0 : VERTICAL_PADDING;

Expand All @@ -736,8 +734,8 @@ class BaseViewer {
scale = Math.min(Math.abs(widthScale), Math.abs(heightScale));
break;
default:
console.error(`${this._name}.scrollPageIntoView: "${dest[1].name}" ` +
'is not a valid destination type.');
console.error(`${this._name}.scrollPageIntoView: ` +
`"${destArray[1].name}" is not a valid destination type.`);
return;
}

Expand All @@ -747,7 +745,7 @@ class BaseViewer {
this.currentScaleValue = DEFAULT_SCALE_VALUE;
}

if (scale === 'page-fit' && !dest[4]) {
if (scale === 'page-fit' && !destArray[4]) {
this._scrollIntoView({
pageDiv: pageView.div,
pageNumber,
Expand Down Expand Up @@ -1088,7 +1086,7 @@ class BaseViewer {
if (this._currentScaleValue && isNaN(this._currentScaleValue)) {
this._setScale(this._currentScaleValue, true);
}
this.scrollPageIntoView({ pageNumber, });
this._setCurrentPageNumber(pageNumber, /* resetCurrentPageView = */ true);
this.update();
}

Expand Down Expand Up @@ -1148,7 +1146,7 @@ class BaseViewer {
if (!pageNumber) {
return;
}
this.scrollPageIntoView({ pageNumber, });
this._setCurrentPageNumber(pageNumber, /* resetCurrentPageView = */ true);
this.update();
}
}
Expand Down