Skip to content

Commit

Permalink
chore: return the original input path, and add a test
Browse files Browse the repository at this point in the history
Signed-off-by: blam <ben@blam.sh>
  • Loading branch information
benjdlambert committed Feb 22, 2024
1 parent 7422430 commit 1ad2b1b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
11 changes: 8 additions & 3 deletions packages/backend-common/src/paths.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import { createMockDirectory } from '@backstage/backend-test-utils';
import { resolveSafeChildPath } from './paths';
import fs from 'fs/promises';

describe('paths', () => {
describe('resolveSafeChildPath', () => {
Expand All @@ -42,9 +41,9 @@ describe('paths', () => {
);
});

it('should resolve to the full path if the target is inside the directory', async () => {
it('should resolve to the full path if the target is inside the directory', () => {
expect(resolveSafeChildPath(workspacePath, './README.md')).toEqual(
`${await fs.realpath(workspacePath)}/README.md`,
`${workspacePath}/README.md`,
);
});

Expand All @@ -60,5 +59,11 @@ describe('paths', () => {
'Relative path is not allowed to refer to a directory outside its parent',
);
});

it('should not throw an error when a folder is referenced that doesnt already exist', () => {
expect(resolveSafeChildPath(workspacePath, 'template')).toEqual(
`${workspacePath}/template`,
);
});
});
});
3 changes: 2 additions & 1 deletion packages/backend-common/src/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ export function resolveSafeChildPath(base: string, path: string): string {
);
}

return targetPath;
// Don't return the resolved path as the original could be a symlink
return resolvePath(base, path);
}

function resolveRealPath(path: string): string {
Expand Down

0 comments on commit 1ad2b1b

Please sign in to comment.