Skip to content

Commit b5763ea

Browse files
committed
Fix handling of absolute paths
This commit fixes the handling of absolute paths, switching from `path.join()` to `path.isAbsolute()` to handle differing behavior for different platforms. `path.join()` works differently for Windows paths and Linux paths. `path.join(".", "C:\\") === "C:\\"` `path.join(".", "/home/test") === "home/test"` The latter is missing a leading `/` and thus is no longer an absolute path. As described in [this issue](GHSA-37v4-cwgp-x353), there was a NodeJS [security vulnerability](https://nodejs.org/en/blog/vulnerability/january-2025-security-releases) that caused the behavior of `path.join()` to be changed. Newer versions of Node will return a relative path in these instances, so `path.join(".", "C:\\") === ".\\C:\\"`.
1 parent fabcbb5 commit b5763ea

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

lib/java-caller.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,8 @@ class JavaCaller {
207207
let allArgs = [];
208208
allArgs.push(...javaArgs);
209209
if (this.jar) {
210-
const jarPath = path.join(this.rootPath, this.jar);
210+
const jarPath = path.isAbsolute(this.jar) ? this.jar : path.join(this.rootPath, this.jar);
211+
211212
allArgs.push(
212213
...[
213214
"-jar",

test/java-caller.test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,10 @@ describe("Call with classes", () => {
177177
});
178178

179179
it("Should work with an absolute path", async () => {
180+
const absolutePath = path.join(process.cwd(), "test/java/jar/JavaCallerTesterRunnable.jar");
181+
180182
const java = new JavaCaller({
181-
jar: path.join(process.cwd(), "test/java/jar/JavaCallerTesterRunnable.jar"),
183+
jar: absolutePath,
182184
});
183185
const { status, stdout, stderr } = await java.run();
184186

0 commit comments

Comments
 (0)