From 2c4f30deea107bf42df4de1d3e7373d52d0d35f5 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 712bd87d85f6e6..3439857a042156 100644 --- a/lib/internal/fs/utils.js +++ b/lib/internal/fs/utils.js @@ -336,6 +336,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. @@ -347,7 +348,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 d1784fdd3a07f4..28938f41d66010 100644 --- a/test/parallel/test-fs-symlink.js +++ b/test/parallel/test-fs-symlink.js @@ -56,6 +56,10 @@ fs.symlink(linkData, linkPath, common.mustCall(function(err) { assert.ifError(err); assert.strictEqual(destination, linkData); })); + + tmpdir.refresh(); + // Fixes: https://github.com/nodejs/node/issues/34514 + fs.symlinkSync(Buffer.from(linkData), linkPath); })); // Test invalid symlink