node icon indicating copy to clipboard operation
node copied to clipboard

Behavior of `realpath` with an empty string argument

Open avivkeller opened this issue 1 year ago • 2 comments

Refs: #35403

Currently, the project has 2 outcomes for different realpath functions with empty string arguments:

fs.realpathSync('') // Returns CWD
await util.promisify(fs.realpath)('') // Returns CWD

await fs.promises.realpath('') // ENOENT Error
fs.realpathSync.native('') // ENOENT Error
await util.promisify(fs.realpath.native)('') // ENOENT Error

IMO, this should be standardized to (A) Always throw (B) Always return CWD (C) Return CWD for non-.native calls, throw otherwise

avivkeller avatar Jun 28 '24 21:06 avivkeller

There is always going to be a discrepency between fs.realpath() and fs.promises.realpath().

For some history fs.realpath() and fs.realpathSync() differ from native realpath and have behaviour oddities that were too breaking to change. At one point it was changed to call the native realpath but there were a number of issues that resulted in the implementation being reverted, see https://github.com/nodejs/node/issues/7726.

When fs.promises.realpath() was added the decision was made to call the native realpath since it was a new API and be consistent with fs.realpath.native().

richardlau avatar Jun 28 '24 22:06 richardlau

I'm aware that there historically have been discrepency, but I think that the discrepencies (for errors) should be handled, or noted in the docs.

avivkeller avatar Jun 28 '24 22:06 avivkeller