chore: return the original input path, and add a test
Signed-off-by: blam <ben@blam.sh>
This commit is contained in:
@@ -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`,
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user