Skip to content

Commit

Permalink
Guard against input and output being on different fs roots
Browse files Browse the repository at this point in the history
  • Loading branch information
niloc132 committed Nov 4, 2023
1 parent c580422 commit d4330e7
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/com/google/javascript/jscomp/CommandLineRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.TreeMap;
import java.util.logging.Level;
Expand Down Expand Up @@ -2094,14 +2095,18 @@ private ClosureBundler getBundler() {
@Override
protected void prepForBundleAndAppendTo(Appendable out, CompilerInput input, String content, String outputPath)
throws IOException {
String pathToInput = new File(input.getName()).getCanonicalPath();
String pathToOutput = new File(outputPath).getParentFile().getCanonicalPath();
String relativePath = Paths.get(pathToOutput).relativize(Paths.get(pathToInput)).toString();

ClosureBundler bundler;
if (!relativePath.startsWith("..")) {
bundler = getBundler().useEval(true).withSourceUrl(relativePath);
Path pathToInput = Paths.get(new File(input.getName()).getCanonicalPath());
Path pathToOutput = Paths.get(new File(outputPath).getParentFile().getCanonicalPath());
final ClosureBundler bundler;
if (Objects.equals(pathToInput.getRoot(), pathToOutput.getRoot())) {
String relativePath = pathToOutput.relativize(pathToInput).toString();
if (!relativePath.startsWith("..")) {
bundler = getBundler().useEval(true).withSourceUrl(relativePath);
} else {
bundler = getBundler();
}
} else {
// Didn't share a root (such as two different windows drives), must not relativize
bundler = getBundler();
}

Expand Down

0 comments on commit d4330e7

Please sign in to comment.