mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 06:58:54 +00:00
fix(fs): handle '.' path normalization on Windows (#26634)
## Summary
- Fix path normalization for "." on Windows where `normalizeStringBuf`
was incorrectly stripping it to an empty string
- This caused `existsSync('.')`, `statSync('.')`, and other fs
operations to fail on Windows
## Test plan
- Added regression test `test/regression/issue/26631.test.ts` that tests
`existsSync`, `exists`, `statSync`, and `stat` for both `.` and `..`
paths
- All tests pass locally with `bun bd test
test/regression/issue/26631.test.ts`
- Verified code compiles on all platforms with `bun run zig:check-all`
Fixes #26631
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Bot <claude-bot@bun.sh>
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -649,6 +649,10 @@ pub const PathLike = union(enum) {
|
||||
const normal = path_handler.normalizeBuf(resolve, b, .windows);
|
||||
return strings.toKernel32Path(@alignCast(std.mem.bytesAsSlice(u16, buf)), normal);
|
||||
}
|
||||
// Handle "." specially since normalizeStringBuf strips it to an empty string
|
||||
if (s.len == 1 and s[0] == '.') {
|
||||
return strings.toKernel32Path(@alignCast(std.mem.bytesAsSlice(u16, buf)), ".");
|
||||
}
|
||||
const normal = path_handler.normalizeStringBuf(s, b, true, .windows, false);
|
||||
return strings.toKernel32Path(@alignCast(std.mem.bytesAsSlice(u16, buf)), normal);
|
||||
}
|
||||
|
||||
42
test/regression/issue/26631.test.ts
Normal file
42
test/regression/issue/26631.test.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import { expect, test } from "bun:test";
|
||||
import { existsSync, statSync } from "node:fs";
|
||||
import { exists, stat } from "node:fs/promises";
|
||||
|
||||
// https://github.com/oven-sh/bun/issues/26631
|
||||
// Path resolution fails for current directory '.' on Windows
|
||||
|
||||
test("existsSync('.') should return true", () => {
|
||||
expect(existsSync(".")).toBe(true);
|
||||
});
|
||||
|
||||
test("exists('.') should return true", async () => {
|
||||
expect(await exists(".")).toBe(true);
|
||||
});
|
||||
|
||||
test("statSync('.') should return directory stats", () => {
|
||||
const stats = statSync(".");
|
||||
expect(stats.isDirectory()).toBe(true);
|
||||
});
|
||||
|
||||
test("stat('.') should return directory stats", async () => {
|
||||
const stats = await stat(".");
|
||||
expect(stats.isDirectory()).toBe(true);
|
||||
});
|
||||
|
||||
test("existsSync('..') should return true", () => {
|
||||
expect(existsSync("..")).toBe(true);
|
||||
});
|
||||
|
||||
test("exists('..') should return true", async () => {
|
||||
expect(await exists("..")).toBe(true);
|
||||
});
|
||||
|
||||
test("statSync('..') should return directory stats", () => {
|
||||
const stats = statSync("..");
|
||||
expect(stats.isDirectory()).toBe(true);
|
||||
});
|
||||
|
||||
test("stat('..') should return directory stats", async () => {
|
||||
const stats = await stat("..");
|
||||
expect(stats.isDirectory()).toBe(true);
|
||||
});
|
||||
Reference in New Issue
Block a user