Skip to content

Commit

Permalink
fs: fix when path is buffer on fs.symlinkSync
Browse files Browse the repository at this point in the history
PR-URL: #34540
Fixes: #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>
  • Loading branch information
himself65 committed Jul 30, 2020
1 parent 019ea07 commit 2c4f30d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/internal/fs/utils.js
Expand Up @@ -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.
Expand All @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions test/parallel/test-fs-symlink.js
Expand Up @@ -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
Expand Down

0 comments on commit 2c4f30d

Please sign in to comment.