Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions packages/core/src/utils/paths.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,22 @@ describe('resolveToRealPath', () => {
/Infinite recursion detected/,
);
});

it('should return path as-is if fs.realpathSync and fs.lstatSync fail with ENAMETOOLONG', () => {
vi.spyOn(fs, 'realpathSync').mockImplementation(() => {
const err = new Error('File name too long') as NodeJS.ErrnoException;
err.code = 'ENAMETOOLONG';
throw err;
});
vi.spyOn(fs, 'lstatSync').mockImplementation(() => {
const err = new Error('File name too long') as NodeJS.ErrnoException;
err.code = 'ENAMETOOLONG';
throw err;
});

const longPath = path.resolve('a'.repeat(5000));
expect(resolveToRealPath(longPath)).toBe(longPath);
});
});

describe('makeRelative', () => {
Expand Down
8 changes: 5 additions & 3 deletions packages/core/src/utils/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ function robustRealpath(p: string, visited = new Set<string>()): string {
e &&
typeof e === 'object' &&
'code' in e &&
(e.code === 'ENOENT' || e.code === 'EISDIR')
(e.code === 'ENOENT' || e.code === 'EISDIR' || e.code === 'ENAMETOOLONG')
) {
try {
const stat = fs.lstatSync(p);
Expand All @@ -435,13 +435,15 @@ function robustRealpath(p: string, visited = new Set<string>()): string {
}
} catch (lstatError: unknown) {
// Not a symlink, or lstat failed. Re-throw if it's not an expected
// ENOENT (e.g., a permissions error), otherwise resolve parent.
// error (e.g., a permissions error), otherwise resolve parent.
if (
!(
lstatError &&
typeof lstatError === 'object' &&
'code' in lstatError &&
(lstatError.code === 'ENOENT' || lstatError.code === 'EISDIR')
(lstatError.code === 'ENOENT' ||
lstatError.code === 'EISDIR' ||
lstatError.code === 'ENAMETOOLONG')
)
) {
throw lstatError;
Expand Down
Loading