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

Paths with trailing slashes should be treated as directories #1051

Open
NotWearingPants opened this issue Aug 2, 2024 · 3 comments
Open

Comments

@NotWearingPants
Copy link

NotWearingPants commented Aug 2, 2024

Using memfs:

const { fs } = require('memfs');
fs.writeFileSync('/foo', 'hello');
console.log(fs.readFileSync('/foo/', 'utf8')); // logs 'hello'

Using the builtin fs (on Linux):

const fs = require('node:fs');
fs.writeFileSync('/foo', 'hello');
console.log(fs.readFileSync('/foo/', 'utf8')); // throws ENOTDIR

Using the builtin fs (on Windows):

const fs = require('node:fs');
fs.writeFileSync('C:/foo', 'hello');
console.log(fs.readFileSync('C:/foo/', 'utf8')); // logs 'hello'

I think a trailing slash means the path is intended to point at a folder, so trying to read from it should throw.

Not sure why Windows is weird, maybe the behavior should differ based on isWin.


Tested with memfs v4.11.1 and Node.js v20.12.2

@G-Rath
Copy link
Collaborator

G-Rath commented Aug 2, 2024

Have you tried your Windows test with \\ instead of /?

@NotWearingPants
Copy link
Author

Yes, it still reads the file successfully

@G-Rath
Copy link
Collaborator

G-Rath commented Aug 2, 2024

hmm interesting - that might be a bug in Node

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants