Skip to content

Commit 9b8596a

Browse files
himself65targos
authored andcommitted
fs: fix when path is buffer on fs.symlinkSync
PR-URL: #34540 Fixes: #34514 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anto Aravinth <[email protected]> Reviewed-By: Pranshu Srivastava <[email protected]>
1 parent 00b9d95 commit 9b8596a

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
@@ -349,6 +349,7 @@ function preprocessSymlinkDestination(path, type, linkPath) {
349349
// No preprocessing is needed on Unix.
350350
return path;
351351
}
352+
path = '' + path;
352353
if (type === 'junction') {
353354
// Junctions paths need to be absolute and \\?\-prefixed.
354355
// A relative target is relative to the link's parent directory.
@@ -360,7 +361,7 @@ function preprocessSymlinkDestination(path, type, linkPath) {
360361
return pathModule.toNamespacedPath(path);
361362
}
362363
// Windows symlinks don't tolerate forward slashes.
363-
return ('' + path).replace(/\//g, '\\');
364+
return path.replace(/\//g, '\\');
364365
}
365366

366367
// Constructor for file stats.

test/parallel/test-fs-symlink.js

+4
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ fs.symlink(linkData, linkPath, common.mustSucceed(() => {
5151
fs.readlink(linkPath, common.mustSucceed((destination) => {
5252
assert.strictEqual(destination, linkData);
5353
}));
54+
55+
tmpdir.refresh();
56+
// Fixes: https://github.com./nodejs/node/issues/34514
57+
fs.symlinkSync(Buffer.from(linkData), linkPath);
5458
}));
5559

5660
// Test invalid symlink

0 commit comments

Comments
 (0)