Skip to content

Commit

Permalink
Merge pull request #1092 from NASA-PDS/issue_1058
Browse files Browse the repository at this point in the history
Update cucumber tests to fix several issues introduced with improved error handling
  • Loading branch information
jordanpadams authored Jan 7, 2025
2 parents 80ad36a + 0014505 commit 2eaff03
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 30 deletions.
12 changes: 9 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,13 @@
</plugin>
</plugins>
</build>

<repositories>
<repository>
<id>OSGeo</id>
<name>OSGeo</name>
<url> https://repo.osgeo.org/repository/release/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.verapdf</groupId>
Expand Down Expand Up @@ -276,8 +282,8 @@
</dependency>
<dependency>
<groupId>xml-resolver</groupId>
<artifactId>xml-resolver</artifactId>
<version>1.2</version>
<artifactId>xml-resolver-patched</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/gov/nasa/pds/tools/util/PDFUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.nio.file.Paths;
import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.verapdf.gf.foundry.VeraGreenfieldFoundryProvider;
Expand Down Expand Up @@ -90,6 +93,11 @@ private boolean validatePDF(String baseDir, URI uri, String pdfRef) throws IOExc
boolean pdfValidateFlag = false;

try {
// make sure file is not 0 bytes in length
if (FileUtils.sizeOf(new File(pdfRef)) == 0) {
this.errorMessage = "Zero length file is an invalid PDF file.";
return pdfValidateFlag;
}
// Create a parser and auto-detect flavour
PDFAParser parser = Foundries.defaultInstance().createParser(new FileInputStream(pdfRef));
PDFAFlavour detectedFlavour = parser.getFlavour();
Expand Down Expand Up @@ -150,7 +158,7 @@ public synchronized boolean validateFileStandardConformity(String baseDir, Strin
// Get the location of the PDF file.
URI uri = null;
try {
uri = target.toURI();
uri = new URI(URLEncoder.encode(URLDecoder.decode(target.toString(), "UTF-8"), "UTF-8"));
} catch (URISyntaxException e) {
// Should never happen
// but if it does, print an error message and returns false for pdfValidateFlag.
Expand All @@ -173,7 +181,7 @@ public synchronized boolean validateFileStandardConformity(String baseDir, Strin
}

// Build the full pathname of the PDF file.
String pdfRef = parent + (parent.endsWith(File.separator) ? "" : File.separator) + pdfBase;
String pdfRef = parent + (parent.endsWith(File.separator) ? "" : File.separator) + URLDecoder.decode(pdfBase, "UTF-8");
LOG.debug("validateFileStandardConformity:parent,pdfBase,pdfRef [{}],[{}],[{}]", parent,
pdfBase, pdfRef);
LOG.debug("validateFileStandardConformity:parent,pdfBase,pdfRef,uri [{}],[{}],[{}],{}", parent,
Expand Down
Loading

0 comments on commit 2eaff03

Please sign in to comment.