From 66fccd860bd18ba75fb8b9e55add79f48173acf4 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Fri, 4 Jan 2019 10:33:15 +0100 Subject: [PATCH] Adjust how `AnnotationBorderStyle.setWidth` handles the input being a `Name` (issue 10385) In order to be consistent with the behaviour in Adobe Reader, the width will now always be set to zero when the input is a `Name`. --- src/core/annotation.js | 3 ++- test/unit/annotation_spec.js | 11 +++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/core/annotation.js b/src/core/annotation.js index 352aafac0..db95bd6be 100644 --- a/src/core/annotation.js +++ b/src/core/annotation.js @@ -485,7 +485,8 @@ class AnnotationBorderStyle { // 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); + this.width = 0; // This is consistent with the behaviour in Adobe Reader. + return; } if (Number.isInteger(width)) { this.width = width; diff --git a/test/unit/annotation_spec.js b/test/unit/annotation_spec.js index 0f131a3e4..07c567972 100644 --- a/test/unit/annotation_spec.js +++ b/test/unit/annotation_spec.js @@ -236,12 +236,15 @@ describe('annotation', function() { expect(borderStyle.width).toEqual(1); }); - it('should set/get a valid width, when the input is a `Name` (issue 10385)', + it('should set the width to zero, when the input is a `Name` (issue 10385)', function() { - const borderStyle = new AnnotationBorderStyle(); - borderStyle.setWidth(Name.get('0')); + const borderStyleZero = new AnnotationBorderStyle(); + borderStyleZero.setWidth(Name.get('0')); + const borderStyleFive = new AnnotationBorderStyle(); + borderStyleFive.setWidth(Name.get('5')); - expect(borderStyle.width).toEqual(0); + expect(borderStyleZero.width).toEqual(0); + expect(borderStyleFive.width).toEqual(0); }); it('should set and get a valid style', function() {