Skip to content

Paths with trailing slashes should be treated as directories #1051

@SnirBroshi

Description

@SnirBroshi

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

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions