fix: resolve absolute symlink targets correctly when packing#452
Merged
Conversation
Use path.resolve instead of path.join in Filesystem.resolveLink so that
an absolute symlink target is honored as an absolute path rather than
being concatenated onto the parent directory path.
Previously path.join swallowed the leading separator of an absolute
target, which:
- turned an absolute in-package target into a broken relative link
that dangles on extract, and
- silently bypassed the out-of-package guard for absolute targets
pointing outside the package.
path.resolve handles both absolute and relative targets through a single
code path; relative targets are unaffected.
Adds regression tests for an absolute in-package target (stored as the
correct relative link) and an absolute out-of-package target (rejected
with the existing 'links out of the package' error).
Fixes #366
MarshallOfSound
approved these changes
Jun 28, 2026
MarshallOfSound
marked this pull request as ready for review
June 28, 2026 05:27
erikian
approved these changes
Jun 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requested by Samuel Attard · Slack thread
Fixes #366
Before / After
Before: When a symlink's target was an absolute path,
Filesystem.resolveLinkusedpath.join(parentPath, symlink).path.joinignores the fact thatsymlinkmay itself be absolute and simply concatenates it ontoparentPath, swallowing the leading separator. This had two bad consequences:subdir/package/inner/file.txtinstead ofinner/file.txt), so it dangled when the archive was extracted.After: Absolute targets resolve to the path they actually point at. In-package absolute targets are stored as the correct in-package relative link, and out-of-package absolute targets resolve to a
../-prefixed path that the existingisAbsolute/..guard rejects, exactly like a relative escape (e.g.../../etc/passwd).How
One-line change in
src/filesystem.ts:path.join(parentPath, symlink)→path.resolve(parentPath, symlink).path.resolvehonors an absolute target as-is while treating a relative target identically to before, so absolute and relative targets now flow through a single, correct code path. Relative-target behavior is unchanged.Tests
Added regression tests in
test/filesystem-spec.ts(the existinginsertLink symlink validationblock):links out of the packageerror.Both tests fail on
mainand pass with this change. The symlinks are constructed at runtime viainsertLinkarguments (no absolute-path-dependent fixtures committed).Generated by Claude Code