Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #12360 #12364

Merged
merged 3 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
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
8 changes: 5 additions & 3 deletions src/bun.js/webcore/blob/WriteFile.zig
Original file line number Diff line number Diff line change
Expand Up @@ -507,9 +507,11 @@ pub const WriteFileWindows = struct {
fn onMkdirpComplete(this: *WriteFileWindows) void {
this.event_loop.unrefConcurrently();

if (this.err) |err| {
this.throw(err);
bun.default_allocator.free(err.path);
const err = this.err;
this.err = null;
if (err) |err_| {
this.throw(err_);
bun.default_allocator.free(err_.path);
return;
}

Expand Down
40 changes: 40 additions & 0 deletions test/regression/issue/012360.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// https://github.com/oven-sh/bun/issues/12360
import { test, expect } from "bun:test";
import { fileURLToPath, pathToFileURL } from "bun";
import { tmpdirSync } from "harness";
import { join } from "path";

export async function validatePath(path: URL): Promise<URL | string> {
const filePath = fileURLToPath(path);

if (await Bun.file(filePath).exists()) {
return pathToFileURL(filePath);
} else {
return "";
}
}

test("validate executable given in the config using `validatePath`: invalid value", async () => {
const dir = tmpdirSync();

const filePath = join(dir, "./sample.exe");

const newFilePath = await validatePath(pathToFileURL(filePath));

expect(newFilePath).toBe("");
});

test("validate executable given in the config using `validatePath`: expected real implementation", async () => {
const dir = tmpdirSync();
const editorPath: URL | string = pathToFileURL(join(dir, "./metaeditor64.exe"));
const terminalPath: URL | string = pathToFileURL(join(dir, "./terminal64.exe"));

await Bun.write(editorPath.pathname, "im a editor");
await Bun.write(terminalPath.pathname, "im a terminal");

const newEditorPath = <URL>await validatePath(editorPath);
const newTerminalPath = <URL>await validatePath(terminalPath);

expect(newEditorPath.pathname).toBe(editorPath.pathname);
expect(newTerminalPath.pathname).toBe(terminalPath.pathname);
});
Loading