Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,14 @@ public boolean perform(AbstractBuild build, Launcher launcher, BuildListener lis
}

private FilePath getSourceDirectory(FilePath basePath) throws IOException, InterruptedException {
String subdirectory = this.subdirectory.trim().length() > 0 ? this.subdirectory.trim() : "";
String subdirectory = StringUtils.trimToEmpty(this.subdirectory);
if (!subdirectory.isEmpty() && !subdirectory.startsWith("/")) {
subdirectory = "/" + subdirectory;
}
FilePath sourcePath = basePath.withSuffix(subdirectory).absolutize();
File sourceDirectory = new File(sourcePath.getRemote());
if (!sourceDirectory.isDirectory() || !isSubDirectory(basePath, sourcePath)) {
throw new IllegalArgumentException("Provided path is not a subdirectory of the workspace: " + sourcePath );
if (!sourcePath.isDirectory() || !isSubDirectory(basePath, sourcePath)) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can isSubDirectory(basePath, sourcePath)) ever be false? Since we said FilePath sourcePath = basePath.withSuffix(subdirectory).absolutize();

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it could be false if subdirectory contains something like "../non-workspace-dir". I guess that's what the original author wanted to check.

throw new IllegalArgumentException("Provided path (resolved as '" + sourcePath
+"') is not a subdirectory of the workspace (resolved as '" + basePath + "')");
}
return sourcePath;
}
Expand Down