Skip to content

Commit f3612fc

Browse files
committed
readlink should normalize against parent, not against root
1 parent 1edf19d commit f3612fc

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

src/library_fs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ mergeInto(LibraryManager.library, {
838838
if (!link.node_ops.readlink) {
839839
throw new FS.ErrnoError(ERRNO_CODES.EINVAL);
840840
}
841-
return PATH.resolve('.', link.node_ops.readlink(link));
841+
return PATH.resolve(FS.getPath(lookup.node.parent), link.node_ops.readlink(link));
842842
},
843843
stat: function(path, dontFollow) {
844844
var lookup = FS.lookupPath(path, { follow: !dontFollow });

src/library_nodefs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ mergeInto(LibraryManager.library, {
205205
try {
206206
path = fs.readlinkSync(path);
207207
path = NODEJS_PATH.relative(NODEJS_PATH.resolve(node.mount.opts.root), path);
208-
return PATH.join(node.mount.mountpoint, path);
208+
return path;
209209
} catch (e) {
210210
if (!e.code) throw e;
211211
throw new FS.ErrnoError(ERRNO_CODES[e.code]);

tests/unistd/links.out

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ symlink/normal
2121
ret: 0
2222
errno: 0
2323
readlink(created link)
24-
ret: 29
24+
ret: 36
2525
errno: 0
26-
result: /working/new-nonexistent-path
26+
result: /working/folder/new-nonexistent-path
2727

2828
readlink(short buffer)
2929
ret: 3
3030
errno: 0
31-
result: /thrking/new-nonexistent-path
31+
result: /thrking/folder/new-nonexistent-path

0 commit comments

Comments
 (0)