Skip to content

Commit a7ed6f2

Browse files
committed
test: add safety check for rel to absolute paths
1 parent dce0bc7 commit a7ed6f2

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/lib/tools.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ export function resolveVariables(
275275
* @returns absolute path relative to the workspace root
276276
*/
277277
export function pathRelToAbs(relPath: string, uri: vscode.Uri): string | undefined {
278+
if (path.isAbsolute(relPath)) return relPath;
278279
const root = getOuterMostWorkspaceFolder(vscode.workspace.getWorkspaceFolder(uri));
279280
if (root === undefined) return undefined;
280281
return path.join(root.uri.fsPath, relPath);

test/unitTest/tools.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,15 @@ suite('Tools tests', () => {
5454
test('Resolve local paths: undefined', () => {
5555
const root = Uri.parse('/home/user/project');
5656
const absPath = pathRelToAbs('./sample.f90', root);
57-
console.log(absPath, root);
5857
assert.strictEqual(absPath, undefined);
5958
});
6059

60+
test('Resolve local paths: absolute', () => {
61+
const root = Uri.parse('/home/user/project');
62+
const absPath = pathRelToAbs(path.resolve(process.cwd()), root);
63+
assert.strictEqual(absPath, path.resolve(process.cwd()));
64+
});
65+
6166
test('Resolve local paths: workspace selection', () => {
6267
const root = Uri.parse(path.resolve(__dirname, '../../../test/fortran'));
6368
const absPath = pathRelToAbs('./sample.f90', root);

0 commit comments

Comments
 (0)