Skip to content

Commit bb45377

Browse files
author
Maruan Sahyoun
committed
PDFBOX-6207: handle empty string in /Opt entry
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1934716 13f79535-47bb-0310-9956-ffa450edef68
1 parent 6358adf commit bb45377

3 files changed

Lines changed: 48 additions & 0 deletions

File tree

pdfbox/pom.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,19 @@
959959
<sha512>83bc557e6f7d3e98de6e81168b2e2fb3def5025cc5fab1ddb3ef658505351c615253587f09b93503bb73a6225f3d3898be894e9d05dba8d464f4dd9c54514bc3</sha512>
960960
</configuration>
961961
</execution>
962+
<execution>
963+
<id>PDFBOX-6207</id>
964+
<phase>generate-test-resources</phase>
965+
<goals>
966+
<goal>wget</goal>
967+
</goals>
968+
<configuration>
969+
<url>https://issues.apache.org/jira/secure/attachment/13082507/form_with_checkbox.pdf</url>
970+
<outputDirectory>${project.build.directory}/pdfs</outputDirectory>
971+
<outputFileName>PDFBOX-6207.pdf</outputFileName>
972+
<sha512>3c8020c1114e2267fdc4e525eed04fd452c75eab4fb0c5d60340983d91af52aca330383a4430934de82e73ddfcd17eec55f1426bd0756b7d11510fadf1043cf9</sha512>
973+
</configuration>
974+
</execution>
962975
</executions>
963976
</plugin>
964977
</plugins>

pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDButton.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,11 @@ public List<String> getExportValues()
253253

254254
if (value instanceof COSString)
255255
{
256+
COSString stringValue = (COSString) value;
257+
if (stringValue.getString().isEmpty())
258+
{
259+
return Collections.emptyList();
260+
}
256261
return Collections.singletonList(((COSString) value).getString());
257262
}
258263
else if (value instanceof COSArray)

pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/TestCheckBox.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,18 @@
1616
*/
1717
package org.apache.pdfbox.pdmodel.interactive.form;
1818

19+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
1920
import static org.junit.jupiter.api.Assertions.assertEquals;
2021
import static org.junit.jupiter.api.Assertions.assertNotNull;
2122
import static org.junit.jupiter.api.Assertions.assertNull;
2223
import static org.junit.jupiter.api.Assertions.assertTrue;
2324

25+
import java.io.File;
2426
import java.io.IOException;
2527
import java.util.ArrayList;
2628
import java.util.List;
2729

30+
import org.apache.pdfbox.Loader;
2831
import org.apache.pdfbox.cos.COSArray;
2932
import org.apache.pdfbox.cos.COSDictionary;
3033
import org.apache.pdfbox.cos.COSName;
@@ -125,4 +128,31 @@ void testCheckBoxNoAppearance() throws IOException
125128
assertEquals("Off", checkBox.getValue());
126129
}
127130
}
131+
132+
/**
133+
* PDFBOX-6207 Invalid /Opt entry. String instead of array of strings.
134+
*
135+
* @throws IOException
136+
*/
137+
@Test
138+
void testPDFBox6207() throws IOException
139+
{
140+
File pdfFile = new File("target/pdfs/PDFBOX-6207.pdf");
141+
142+
if (!pdfFile.exists())
143+
{
144+
return; // Skip test if PDF not available
145+
}
146+
147+
try (PDDocument testPdf = Loader.loadPDF(pdfFile))
148+
{
149+
PDAcroForm acroForm = testPdf.getDocumentCatalog().getAcroForm();
150+
PDCheckBox field = (PDCheckBox) acroForm.getField("Check_Info_Post_andere");
151+
System.out.println(field.getExportValues());
152+
assertDoesNotThrow(() -> {
153+
field.setValue("Yes");
154+
155+
}, "Setting a valid value of a checkbox with an invalid /Opt entry should not throw an exception");
156+
}
157+
}
128158
}

0 commit comments

Comments
 (0)