Skip to content

Commit e42daf9

Browse files
committed
translate IOException -> Illegal Argument Exception
1 parent b83d42f commit e42daf9

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

plugins/tasks/resource/src/main/java/com/walmartlabs/concord/plugins/resource/ResourceTaskCommon.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,13 @@
3333
import java.io.OutputStream;
3434
import java.nio.file.Files;
3535
import java.nio.file.Path;
36-
import java.nio.file.Paths;
3736
import java.util.Arrays;
3837
import java.util.HashMap;
3938
import java.util.Map;
4039
import java.util.Properties;
4140

4241
import static com.walmartlabs.concord.common.IOUtils.assertInPath;
4342

44-
//import static com.walmartlabs.concord.common.IOUtils.assertInPath;
45-
4643
public class ResourceTaskCommon {
4744

4845
private static final String RESOURCE_PREFIX = "resource_";
@@ -236,17 +233,16 @@ public static String prettyPrintYaml(Object value, int indent) throws IOExceptio
236233
return s;
237234
}
238235

239-
private Path normalizePath(String path) throws IOException {
240-
Path p = Paths.get(path);
241-
assertWorkDirPath(path);
242-
if (p.isAbsolute()) {
243-
return p;
244-
}
245-
return workDir.resolve(path);
236+
private Path normalizePath(String path) {
237+
return assertWorkDirPath(path);
246238
}
247239

248-
private Path assertWorkDirPath(String path) throws IOException {
249-
return assertInPath(workDir, path);
240+
private Path assertWorkDirPath(String path) {
241+
try {
242+
return assertInPath(workDir,path);
243+
} catch (IOException ex) {
244+
throw new IllegalArgumentException("Not authorized to access file outside of working directory: " + path);
245+
}
250246
}
251247

252248
private static ObjectWriter createYamlWriter() {

0 commit comments

Comments
 (0)