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

dirname returns wrong result When the path is the root #3782

Closed
Hanaasagi opened this issue Jul 24, 2023 · 4 comments · Fixed by #3785
Closed

dirname returns wrong result When the path is the root #3782

Hanaasagi opened this issue Jul 24, 2023 · 4 comments · Fixed by #3785
Labels
bug Something isn't working node.js Compatibility with Node.js APIs

Comments

@Hanaasagi
Copy link
Collaborator

What version of Bun is running?

0.7.0

What platform is your computer?

Linux 6.4.4-arch1-1 x86_64 unknown

What steps can reproduce the bug?

const path = require("path");
const assert = require("assert");
assert.strictEqual(path.posix.dirname("/"), "/");

What is the expected behavior?

No `AssertionError``.

What do you see instead?

AssertionError: Expected values to be strictly equal:

'.' !== '/'

 code: "ERR_ASSERTION"

Additional information

I think this bug is related to #2676

Here, the returned value should be determined by more context details instead of returning a ..

bun/src/bun.js/node/types.zig

Lines 1699 to 1702 in 967ccb5

const out = if (isWindows)
std.fs.path.dirnameWindows(base_slice) orelse "."
else
std.fs.path.dirnamePosix(base_slice) orelse ".";

@Hanaasagi Hanaasagi added the bug Something isn't working label Jul 24, 2023
@Hanaasagi
Copy link
Collaborator Author

Hanaasagi commented Jul 24, 2023

After running the dirname related test files in Nodejs, I found some other incompatibilities.

assert.strictEqual(path.posix.dirname("////"), "/");
assert.strictEqual(path.posix.dirname("//a"), "//");
assert.strictEqual(path.win32.dirname("c:\\"), "c:\\");
assert.strictEqual(path.win32.dirname("\\"), "\\");

assert.strictEqual(path.win32.dirname("c:"), "c:");
assert.strictEqual(path.win32.dirname("c:foo"), "c:");
assert.strictEqual(path.win32.dirname("c:foo\\"), "c:");
assert.strictEqual(path.win32.dirname("\\\\unc\\share"), "\\\\unc\\share");
assert.strictEqual(path.win32.dirname("/"), "/");
assert.strictEqual(path.win32.dirname("////"), "/");

Ref: https://github.com/nodejs/node/blob/main/test/parallel/test-path-dirname.js

@Jarred-Sumner
Copy link
Collaborator

I’m surprised we still have these bugs

@Hanaasagi
Copy link
Collaborator Author

I think i can fix this.

@Jarred-Sumner
Copy link
Collaborator

Please do

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working node.js Compatibility with Node.js APIs
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants