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

Fix annotation border style parsing by handling empty dash arrays #17905

Merged
merged 1 commit into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions src/core/annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -1474,9 +1474,9 @@ class AnnotationBorderStyle {
// We validate the dash array, but we do not use it because CSS does not
// allow us to change spacing of dashes. For more information, visit
// http://www.w3.org/TR/css3-background/#the-border-style.
if (Array.isArray(dashArray) && dashArray.length > 0) {
// According to the PDF specification: the elements in `dashArray`
// shall be numbers that are nonnegative and not all equal to zero.
if (Array.isArray(dashArray)) {
// The PDF specification states that elements in the dash array, if
// present, must be non-negative numbers and must not all equal zero.
let isValid = true;
let allZeros = true;
for (const element of dashArray) {
Expand All @@ -1488,7 +1488,7 @@ class AnnotationBorderStyle {
allZeros = false;
}
}
if (isValid && !allZeros) {
if (dashArray.length === 0 || (isValid && !allZeros)) {
this.dashArray = dashArray;

if (forceStyle) {
Expand Down
1 change: 1 addition & 0 deletions test/pdfs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@
!issue11549_reduced.pdf
!issue8097_reduced.pdf
!issue15262.pdf
!issue17904.pdf
!bug1743245.pdf
!quadpoints.pdf
!transparent.pdf
Expand Down
Binary file added test/pdfs/issue17904.pdf
Binary file not shown.
8 changes: 8 additions & 0 deletions test/test_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3858,6 +3858,14 @@
"type": "eq",
"annotations": true
},
{
"id": "issue17904",
"file": "pdfs/issue17904.pdf",
"md5": "4b8f0b565a61bf068ef72d232c997cef",
"rounds": 1,
"type": "eq",
"annotations": true
},
{
"id": "issue6179_reduced",
"file": "pdfs/issue6179_reduced.pdf",
Expand Down
9 changes: 9 additions & 0 deletions test/unit/annotation_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,15 @@ describe("annotation", function () {
expect(borderStyle.dashArray).toEqual([3]);
});

it("should not set the width to zero if the dash array is empty (issue 17904)", function () {
const borderStyle = new AnnotationBorderStyle();
borderStyle.setWidth(3);
borderStyle.setDashArray([]);

expect(borderStyle.width).toEqual(3);
expect(borderStyle.dashArray).toEqual([]);
});

it("should set and get a valid horizontal corner radius", function () {
const borderStyle = new AnnotationBorderStyle();
borderStyle.setHorizontalCornerRadius(3);
Expand Down