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 <jasnell@gmail.com>
Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
Reviewed-By: Pranshu Srivastava <rexagod@gmail.com>
This commit is contained in:
himself65 authored and Michaël Zasso committed 2021-05-01 09:39:06 +02:00
1 parent 00b9d955e9
commit 9b8596a67f
2 files changed
+6 -1

No files matched your search

+2 -1
View File
@@ -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.
+4
View File
@@ -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