Skip to content

Commit cead1a8

Browse files
committed
Update: address review feedback
Signed-off-by: pavanpai769 <151814231+pavanpai769@users.noreply.github.com>
1 parent faaddc8 commit cead1a8

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

java/opendataloader-pdf-core/src/main/java/org/opendataloader/pdf/api/OpenDataLoaderPDF.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020

2121
import java.io.IOException;
2222
import java.nio.file.Files;
23+
import java.nio.file.InvalidPathException;
2324
import java.nio.file.Path;
2425
import java.nio.file.Paths;
26+
import java.util.Locale;
2527
import java.util.logging.Level;
2628
import java.util.logging.Logger;
2729

@@ -54,7 +56,7 @@ public static void processFile(String inputPdfName, Config config) throws IOExce
5456
*
5557
* @param inputPdfName the path to the input file
5658
* @return {@code true} if the path is non-null, points to an existing
57-
* regular file, and has a .pdf extension; {@code false} otherwise
59+
* regular file, and has a .pdf extension; {@code false} otherwise
5860
*/
5961
private static boolean isValidInputFile(String inputPdfName) {
6062

@@ -63,7 +65,14 @@ private static boolean isValidInputFile(String inputPdfName) {
6365
return false;
6466
}
6567

66-
Path path = Paths.get(inputPdfName);
68+
final Path path;
69+
70+
try {
71+
path = Paths.get(inputPdfName);
72+
} catch (InvalidPathException ex) {
73+
LOGGER.log(Level.WARNING, () -> "Invalid file path: " + inputPdfName);
74+
return false;
75+
}
6776

6877
if (!Files.exists(path)) {
6978
LOGGER.log(Level.WARNING, () -> "File does not exist: " + inputPdfName);
@@ -75,7 +84,7 @@ private static boolean isValidInputFile(String inputPdfName) {
7584
return false;
7685
}
7786

78-
if (!inputPdfName.toLowerCase().endsWith(".pdf")) {
87+
if (!path.getFileName().toString().toLowerCase(Locale.ROOT).endsWith(".pdf")) {
7988
LOGGER.log(Level.WARNING, () -> "Not a PDF file: " + inputPdfName);
8089
return false;
8190
}

0 commit comments

Comments
 (0)