Skip to content
Closed
Show file tree
Hide file tree
Changes from 11 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
17 changes: 11 additions & 6 deletions src/resolver/resolve_path.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2048,13 +2048,18 @@ export fn ResolvePath__joinAbsStringBufCurrentPlatformBunString(
const str = in.toUTF8WithoutRef(bun.default_allocator);
defer str.deinit();

const out_slice = joinAbsStringBuf(
globalObject.bunVM().transpiler.fs.top_level_dir,
&join_buf,
&.{str.slice()},
.auto,
);
const cwd = globalObject.bunVM().transpiler.fs.top_level_dir;
const input = str.slice();
const total = cwd.len + input.len + 2;

if (total <= join_buf.len) {
const out_slice = joinAbsStringBuf(cwd, &join_buf, &.{input}, .auto);
return bun.String.cloneUTF8(out_slice);
}

const buf = bun.handleOom(bun.default_allocator.alloc(u8, total));
defer bun.default_allocator.free(buf);
const out_slice = joinAbsStringBuf(cwd, buf, &.{input}, .auto);
return bun.String.cloneUTF8(out_slice);
}

Expand Down
7 changes: 7 additions & 0 deletions test/js/node/url/pathToFileURL.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ test("pathToFileURL doesn't leak memory", () => {
expect([path.join(import.meta.dir, "pathToFileURL-leak-fixture.js")]).toRun();
});

test("pathToFileURL handles relative paths longer than 4096 bytes", () => {
expect([
"-e",
'const p = Buffer.alloc(200000, "a").toString(); const u = Bun.pathToFileURL(p); if (!u.href.endsWith("/" + p)) throw new Error(u.href)',
]).toRun();
});
Comment thread
claude[bot] marked this conversation as resolved.

test("pathToFileURL escapes special characters", () => {
const cases = [
["\0", "%00"], // '\0' == 0x00
Expand Down
Loading