Skip to content

Commit 2c4f30d

Browse files
committed
fs: fix when path is buffer on fs.symlinkSync
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>
1 parent 019ea07 commit 2c4f30d

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

lib/internal/fs/utils.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ function preprocessSymlinkDestination(path, type, linkPath) {
336336
// No preprocessing is needed on Unix.
337337
return path;
338338
}
339+
path = '' + path;
339340
if (type === 'junction') {
340341
// Junctions paths need to be absolute and \\?\-prefixed.
341342
// A relative target is relative to the link's parent directory.
@@ -347,7 +348,7 @@ function preprocessSymlinkDestination(path, type, linkPath) {
347348
return pathModule.toNamespacedPath(path);
348349
}
349350
// Windows symlinks don't tolerate forward slashes.
350-
return ('' + path).replace(/\//g, '\\');
351+
return path.replace(/\//g, '\\');
351352
}
352353

353354
// Constructor for file stats.

test/parallel/test-fs-symlink.js

+4
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ fs.symlink(linkData, linkPath, common.mustCall(function(err) {
5656
assert.ifError(err);
5757
assert.strictEqual(destination, linkData);
5858
}));
59+
60+
tmpdir.refresh();
61+
// Fixes: https://github.com/nodejs/node/issues/34514
62+
fs.symlinkSync(Buffer.from(linkData), linkPath);
5963
}));
6064

6165
// Test invalid symlink

0 commit comments

Comments
 (0)