Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in symlink traversal with indirect targets #1084

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions packages/metro-file-map/src/lib/TreeFS.js
Original file line number Diff line number Diff line change
Expand Up @@ -559,13 +559,13 @@ export default class TreeFS implements MutableFileSystem {
typeof literalSymlinkTarget === 'string',
'Expected symlink target to be populated.',
);
if (path.isAbsolute(literalSymlinkTarget)) {
normalSymlinkTarget = path.relative(this.#rootDir, literalSymlinkTarget);
} else {
normalSymlinkTarget = path.normalize(
path.join(path.dirname(canonicalPathOfSymlink), literalSymlinkTarget),
);
}
const absoluteSymlinkTarget = path.resolve(
this.#rootDir,
canonicalPathOfSymlink,
'..', // Symlink target is relative to its containing directory.
literalSymlinkTarget, // May be absolute, in which case the above are ignored
);
normalSymlinkTarget = path.relative(this.#rootDir, absoluteSymlinkTarget);
this.#cachedNormalSymlinkTargets.set(symlinkNode, normalSymlinkTarget);
return normalSymlinkTarget;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/metro-file-map/src/lib/__tests__/TreeFS-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe.each([['win32'], ['posix']])('TreeFS on %s', platform => {
[p('foo/link-to-another.js'), ['', 0, 0, 0, '', '', p('another.js')]],
[p('../outside/external.js'), ['', 0, 0, 0, '', '', 0]],
[p('bar.js'), ['bar', 234, 0, 0, '', '', 0]],
[p('link-to-foo'), ['', 456, 0, 0, '', '', p('././abnormal/../foo')]],
[p('link-to-foo'), ['', 456, 0, 0, '', '', p('./../project/foo')]],
[p('abs-link-out'), ['', 456, 0, 0, '', '', p('/outside/./baz/..')]],
[p('root'), ['', 0, 0, 0, '', '', '..']],
[p('link-to-nowhere'), ['', 123, 0, 0, '', '', p('./nowhere')]],
Expand Down