Merge pull request #10397 from Snuffleupagus/issue-10385
Ensure that `AnnotationBorderStyle.setWidth` is able to handle the input being a `Name`, to correctly deal with corrupt PDF documents (issue 10385)
This commit is contained in:
commit
d8f201ea2a
@ -482,6 +482,11 @@ class AnnotationBorderStyle {
|
|||||||
* @param {integer} width - The width
|
* @param {integer} width - The width
|
||||||
*/
|
*/
|
||||||
setWidth(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)) {
|
if (Number.isInteger(width)) {
|
||||||
this.width = width;
|
this.width = width;
|
||||||
}
|
}
|
||||||
@ -492,11 +497,11 @@ class AnnotationBorderStyle {
|
|||||||
*
|
*
|
||||||
* @public
|
* @public
|
||||||
* @memberof AnnotationBorderStyle
|
* @memberof AnnotationBorderStyle
|
||||||
* @param {Object} style - The style object
|
* @param {Name} style - The annotation style.
|
||||||
* @see {@link shared/util.js}
|
* @see {@link shared/util.js}
|
||||||
*/
|
*/
|
||||||
setStyle(style) {
|
setStyle(style) {
|
||||||
if (!style) {
|
if (!isName(style)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
switch (style.name) {
|
switch (style.name) {
|
||||||
|
@ -236,6 +236,14 @@ describe('annotation', function() {
|
|||||||
expect(borderStyle.width).toEqual(1);
|
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() {
|
it('should set and get a valid style', function() {
|
||||||
const borderStyle = new AnnotationBorderStyle();
|
const borderStyle = new AnnotationBorderStyle();
|
||||||
borderStyle.setStyle(Name.get('D'));
|
borderStyle.setStyle(Name.get('D'));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user