From 9b8596a67f54dab5aeebe5b399a9a9538f8a2297 Mon Sep 17 00:00:00 2001 From: himself65 Date: Tue, 28 Jul 2020 23:14:00 +0800 Subject: [PATCH] fs: fix when path is buffer on fs.symlinkSync PR-URL: https://github.com/nodejs/node/pull/34540 Fixes: https://github.com/nodejs/node/issues/34514 Reviewed-By: James M Snell Reviewed-By: Anto Aravinth Reviewed-By: Pranshu Srivastava --- lib/internal/fs/utils.js | 3 ++- test/parallel/test-fs-symlink.js | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/internal/fs/utils.js b/lib/internal/fs/utils.js index 3ff3d9c561675c..ee4a1a63b35adc 100644 --- a/lib/internal/fs/utils.js +++ b/lib/internal/fs/utils.js @@ -349,6 +349,7 @@ function preprocessSymlinkDestination(path, type, linkPath) { // No preprocessing is needed on Unix. return path; } + path = '' + path; if (type === 'junction') { // Junctions paths need to be absolute and \\?\-prefixed. // A relative target is relative to the link's parent directory. @@ -360,7 +361,7 @@ function preprocessSymlinkDestination(path, type, linkPath) { return pathModule.toNamespacedPath(path); } // Windows symlinks don't tolerate forward slashes. - return ('' + path).replace(/\//g, '\\'); + return path.replace(/\//g, '\\'); } // Constructor for file stats. diff --git a/test/parallel/test-fs-symlink.js b/test/parallel/test-fs-symlink.js index 7c413ca2fedf81..b5c5d46bfbea4b 100644 --- a/test/parallel/test-fs-symlink.js +++ b/test/parallel/test-fs-symlink.js @@ -51,6 +51,10 @@ fs.symlink(linkData, linkPath, common.mustSucceed(() => { fs.readlink(linkPath, common.mustSucceed((destination) => { assert.strictEqual(destination, linkData); })); + + tmpdir.refresh(); + // Fixes: https://github.com/nodejs/node/issues/34514 + fs.symlinkSync(Buffer.from(linkData), linkPath); })); // Test invalid symlink