mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-03-24 18:11:47 +01:00
improved file path validation and error handling
Former-commit-id: 20d4011b031ac956e9803e807de75e7e505172ae
This commit is contained in:
@@ -134,14 +134,20 @@ public final class CliParser {
|
|||||||
* @throws FileNotFoundException is thrown if the path being validated does not exist.
|
* @throws FileNotFoundException is thrown if the path being validated does not exist.
|
||||||
*/
|
*/
|
||||||
private void validatePathExists(String path, String argumentName) throws FileNotFoundException {
|
private void validatePathExists(String path, String argumentName) throws FileNotFoundException {
|
||||||
if (!path.contains("*") && !path.contains("?")) {
|
if (path == null) {
|
||||||
|
final String msg = String.format("Invalid '%s' argument: null", argumentName);
|
||||||
|
throw new FileNotFoundException(msg);
|
||||||
|
} else if (!path.contains("*") && !path.contains("?")) {
|
||||||
final File f = new File(path);
|
final File f = new File(path);
|
||||||
if (!f.exists()) {
|
if (!f.exists()) {
|
||||||
isValid = false;
|
isValid = false;
|
||||||
final String msg = String.format("Invalid '%s' argument: '%s'", argumentName, path);
|
final String msg = String.format("Invalid '%s' argument: '%s'", argumentName, path);
|
||||||
throw new FileNotFoundException(msg);
|
throw new FileNotFoundException(msg);
|
||||||
}
|
}
|
||||||
} // else { // TODO add a validation for *.zip extensions rather then relying on the engine to validate it.
|
} else if (path.startsWith("//") || path.startsWith("\\\\")) {
|
||||||
|
final String msg = String.format("Invalid '%s' argument: '%s'%nUnable to scan paths that start with '//'.", argumentName, path);
|
||||||
|
throw new FileNotFoundException(msg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user