Compare commits

...

6 Commits

Author SHA1 Message Date
Claude Bot
9818ddff6c test: add explicit stdout: "pipe" to all spawn calls
Ensure proc.stdout is explicitly piped so proc.stdout.text() works reliably.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 03:30:37 +00:00
Claude Bot
d9a3343580 test: add positive stdout assertions per review feedback
- Assert stdout contains "SUCCESS: resolved" for UNC paths with server and share
- Assert stdout contains "Error (expected):" for tests that expect graceful error handling
- This verifies the tests actually ran the intended code paths

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 03:25:22 +00:00
Claude Bot
4d15455a0d test: address PR review comments for Windows UNC path tests
- Use String.raw template literals for UNC path strings for readability
- Add exit code assertions to all tests
- Replace negative panic/assertion checks with positive assertions (expect stderr to be empty)
- Replace unused stdout variables with _ where not needed
- Add stdout assertion for test runner to verify "1 pass"
- Add stderr assertion to drive letter test

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 03:18:29 +00:00
Claude Bot
5280dc5659 fix: add bounds check for UNC path validation
Add missing bounds check before slicing input_path to prevent
potential out-of-bounds access. Also simplify by using containsChar
instead of indexOfChar since we only need to check existence.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 02:37:13 +00:00
Claude Bot
8381c12978 fix: add stderr pipe to Windows UNC path tests
Tests were failing because stderr wasn't piped, causing
proc.stderr.text() to be undefined. Added stderr: "pipe"
to all Bun.spawn calls.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-25 06:34:50 +00:00
Claude Bot
a5271eb3ab fix: Windows UNC path validation in dirInfoCachedMaybeLog
Fixed a bug in resolver.zig where UNC paths like \\server\ were incorrectly
accepted as valid. The code was searching for a second slash starting from
the first slash itself, rather than after it.

The bug caused the resolver to accept incomplete UNC paths (server without
share name), leading to assertion failures later when the path was checked
for absoluteness.

Changes:
- Fixed index calculation to search after the first slash (added +1 offset)
- Added clarifying comments explaining the UNC path validation logic
- Added comprehensive tests for Windows UNC path handling

Fixes #17233, #25000

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-25 02:22:17 +00:00
2 changed files with 161 additions and 1 deletions

View File

@@ -2655,10 +2655,15 @@ pub const Resolver = struct {
// Filter out \\hello\, a UNC server path but without a share.
// When there isn't a share name, such path is not considered to exist.
// Valid UNC paths have the format: \\server\share\...
if (bun.strings.hasPrefixComptime(input_path, "\\\\")) {
// Find the first slash after \\, which separates server from share
const first_slash = bun.strings.indexOfChar(input_path[2..], '\\') orelse
return null;
_ = bun.strings.indexOfChar(input_path[2 + first_slash ..], '\\') orelse
// Look for a second slash after the first one to ensure there's a share name
// We need +1 to skip past the first slash itself
const offset = 2 + first_slash + 1;
if (offset >= input_path.len or !bun.strings.containsChar(input_path[offset..], '\\'))
return null;
}
}

View File

@@ -0,0 +1,155 @@
import { describe, expect, test } from "bun:test";
import { bunEnv, bunExe, isWindows, tempDir } from "harness";
import path from "path";
// Tests for Windows UNC path handling in resolver
// Related to issues #17233 and #25000
if (isWindows) {
describe("Windows UNC path handling", () => {
test("Bun.resolve should handle UNC paths with server and share", async () => {
// Create a temporary directory to work with
using dir = tempDir("unc-test", {
"package.json": JSON.stringify({ name: "test", type: "module" }),
"index.js": String.raw`
// This test verifies that UNC paths with proper server and share work
const result = Bun.resolveSync("./foo.js", "\\\\server\\share\\path\\to\\file.js");
console.log("SUCCESS: resolved", result);
`,
});
await using proc = Bun.spawn({
cmd: [bunExe(), path.join(String(dir), "index.js")],
env: bunEnv,
cwd: String(dir),
stdout: "pipe",
stderr: "pipe",
});
const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]);
// Verify the resolve succeeded
expect(stdout).toContain("SUCCESS: resolved");
expect(stderr).toBe("");
expect(exitCode).toBe(0);
});
test("Bun.resolve should handle UNC paths without share gracefully", async () => {
// Create a temporary directory to work with
using dir = tempDir("unc-test-no-share", {
"package.json": JSON.stringify({ name: "test", type: "module" }),
"index.js": String.raw`
// This test verifies that incomplete UNC paths (server without share) are handled gracefully
try {
const result = Bun.resolveSync("./foo.js", "\\\\server\\");
console.log("Resolved:", result);
} catch (error) {
// It's okay to throw an error, but should not panic
console.log("Error (expected):", error.message);
}
`,
});
await using proc = Bun.spawn({
cmd: [bunExe(), path.join(String(dir), "index.js")],
env: bunEnv,
cwd: String(dir),
stdout: "pipe",
stderr: "pipe",
});
const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]);
// Verify the error was caught (not a crash)
expect(stdout).toContain("Error (expected):");
expect(stderr).toBe("");
expect(exitCode).toBe(0);
});
test("Bun.resolve should handle UNC server without trailing slash", async () => {
using dir = tempDir("unc-test-no-trailing", {
"package.json": JSON.stringify({ name: "test", type: "module" }),
"index.js": String.raw`
// Test UNC path with just server name (no trailing slash)
try {
const result = Bun.resolveSync("./foo.js", "\\\\server");
console.log("Resolved:", result);
} catch (error) {
// It's okay to throw an error, but should not panic
console.log("Error (expected):", error.message);
}
`,
});
await using proc = Bun.spawn({
cmd: [bunExe(), path.join(String(dir), "index.js")],
env: bunEnv,
cwd: String(dir),
stdout: "pipe",
stderr: "pipe",
});
const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]);
// Verify the error was caught (not a crash)
expect(stdout).toContain("Error (expected):");
expect(stderr).toBe("");
expect(exitCode).toBe(0);
});
test("module loader should not crash on Windows with UNC-like paths", async () => {
using dir = tempDir("unc-module-loader", {
"package.json": JSON.stringify({ name: "test", type: "module" }),
"test.test.js": `
import { test, expect } from "bun:test";
test("dummy test", () => {
expect(1).toBe(1);
});
`,
});
await using proc = Bun.spawn({
cmd: [bunExe(), "test", "test.test.js"],
env: bunEnv,
cwd: String(dir),
stdout: "pipe",
stderr: "pipe",
});
const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]);
// Verify the test suite passed
expect(stdout).toContain("1 pass");
expect(stderr).toBe("");
expect(exitCode).toBe(0);
});
test("drive letter paths should still work correctly", async () => {
using dir = tempDir("drive-letter-test", {
"package.json": JSON.stringify({ name: "test", type: "module" }),
"foo.js": `export const foo = 42;`,
"index.js": `
import { foo } from "./foo.js";
console.log("foo =", foo);
`,
});
await using proc = Bun.spawn({
cmd: [bunExe(), path.join(String(dir), "index.js")],
env: bunEnv,
cwd: String(dir),
stdout: "pipe",
stderr: "pipe",
});
const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]);
expect(stdout).toContain("foo = 42");
expect(stderr).toBe("");
expect(exitCode).toBe(0);
});
});
} else {
test.skip("Windows UNC path tests only run on Windows", () => {});
}