From 4944e971bbd49ee9d95a50264e8ecb1054010598 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0=20/=20green?= Date: Fri, 29 Dec 2023 04:57:51 +0900 Subject: [PATCH] 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: https://github.com/nodejs/node/issues/51031 PR-URL: https://github.com/nodejs/node/pull/51032 Reviewed-By: LiviaMedeiros Reviewed-By: Benjamin Gruenbaum Reviewed-By: Luigi Pinca Reviewed-By: James M Snell --- lib/internal/fs/promises.js | 2 +- test/parallel/test-fs-long-path.js | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/internal/fs/promises.js b/lib/internal/fs/promises.js index 1e9573d0385..42364c78c66 100644 --- a/lib/internal/fs/promises.js +++ b/lib/internal/fs/promises.js @@ -1160,7 +1160,7 @@ async function realpath(path, options) { options = getOptions(options); path = getValidatedPath(path); return await PromisePrototypeThen( - binding.realpath(path, options.encoding, kUsePromises), + binding.realpath(pathModule.toNamespacedPath(path), options.encoding, kUsePromises), undefined, handleErrorFromBinding, ); diff --git a/test/parallel/test-fs-long-path.js b/test/parallel/test-fs-long-path.js index f3a8ea7a9eb..11724a88dc4 100644 --- a/test/parallel/test-fs-long-path.js +++ b/test/parallel/test-fs-long-path.js @@ -46,4 +46,7 @@ fs.writeFile(fullPath, 'ok', common.mustSucceed(() => { // Tests https://github.com/nodejs/node/issues/39721 fs.realpath.native(fullPath, common.mustSucceed()); + + // Tests https://github.com/nodejs/node/issues/51031 + fs.promises.realpath(fullPath).then(common.mustCall(), common.mustNotCall()); }));