Skip to content

Commit 091098f

Browse files
sapphi-redRafaelGSS
authored andcommitted
fs: fix fs.promises.realpath for long paths on Windows
Unlike other fs functions that work with paths, realpath isn't using pathModule.toNamespacedPath prior to calling libuv function. This is causing issues on windows. Windows long path test is also improved to cover the mentioned issue. Fixes: #51031 PR-URL: #51032 Reviewed-By: LiviaMedeiros <livia@cirno.name> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 652af45 commit 091098f

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

lib/internal/fs/promises.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1160,7 +1160,7 @@ async function realpath(path, options) {
11601160
options = getOptions(options);
11611161
path = getValidatedPath(path);
11621162
return await PromisePrototypeThen(
1163-
binding.realpath(path, options.encoding, kUsePromises),
1163+
binding.realpath(pathModule.toNamespacedPath(path), options.encoding, kUsePromises),
11641164
undefined,
11651165
handleErrorFromBinding,
11661166
);

test/parallel/test-fs-long-path.js

+3
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,7 @@ fs.writeFile(fullPath, 'ok', common.mustSucceed(() => {
4646

4747
// Tests https://github.com/nodejs/node/issues/39721
4848
fs.realpath.native(fullPath, common.mustSucceed());
49+
50+
// Tests https://github.com/nodejs/node/issues/51031
51+
fs.promises.realpath(fullPath).then(common.mustCall(), common.mustNotCall());
4952
}));

0 commit comments

Comments
 (0)