chore: return the original input path, and add a test

Signed-off-by: blam <ben@blam.sh>
This commit is contained in:
blam
2024-02-22 22:16:25 +01:00
parent 742243032f
commit 1ad2b1b61e
2 changed files with 10 additions and 4 deletions
+8 -3
View File
@@ -16,7 +16,6 @@
import { createMockDirectory } from '@backstage/backend-test-utils';
import { resolveSafeChildPath } from './paths';
import fs from 'fs/promises';
describe('paths', () => {
describe('resolveSafeChildPath', () => {
@@ -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`,
);
});
@@ -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`,
);
});
});
});
+2 -1
View File
@@ -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 {