Skip to content

Commit

Permalink
Merge pull request #10397 from Snuffleupagus/issue-10385
Browse files Browse the repository at this point in the history
Ensure that `AnnotationBorderStyle.setWidth` is able to handle the input being a `Name`, to correctly deal with corrupt PDF documents (issue 10385)
  • Loading branch information
timvandermeij committed Dec 31, 2018
2 parents 2cdeb93 + 76a9580 commit d8f201e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/core/annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,11 @@ class AnnotationBorderStyle {
* @param {integer} width - The width
*/
setWidth(width) {
// Some corrupt PDF generators may provide the width as a `Name`,
// rather than as a number (fixes issue 10385).
if (isName(width)) {
width = parseFloat(width.name);
}
if (Number.isInteger(width)) {
this.width = width;
}
Expand All @@ -492,11 +497,11 @@ class AnnotationBorderStyle {
*
* @public
* @memberof AnnotationBorderStyle
* @param {Object} style - The style object
* @param {Name} style - The annotation style.
* @see {@link shared/util.js}
*/
setStyle(style) {
if (!style) {
if (!isName(style)) {
return;
}
switch (style.name) {
Expand Down
8 changes: 8 additions & 0 deletions test/unit/annotation_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,14 @@ describe('annotation', function() {
expect(borderStyle.width).toEqual(1);
});

it('should set/get a valid width, when the input is a `Name` (issue 10385)',
function() {
const borderStyle = new AnnotationBorderStyle();
borderStyle.setWidth(Name.get('0'));

expect(borderStyle.width).toEqual(0);
});

it('should set and get a valid style', function() {
const borderStyle = new AnnotationBorderStyle();
borderStyle.setStyle(Name.get('D'));
Expand Down

0 comments on commit d8f201e

Please sign in to comment.