Skip to content

Commit 8af6b5e

Browse files
authored
fix/ #59 resolve paths for all paths in arguments (#61)
* fix/ #59 resolve paths for all paths in arguments * made determination of path arguments more secure * some formating
1 parent b081b78 commit 8af6b5e

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

src/extension.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as xml2js from 'xml2js';
55

66
import { documentationLinkMap } from './util/documentation';
77
import { runCommand } from './util/scripts';
8-
import { resolvePath, findWorkspaceRoot } from './util/path';
8+
import { looksLikePath, resolvePath, findWorkspaceRoot } from './util/path';
99

1010
enum SeverityNumber {
1111
Info = 0,
@@ -30,6 +30,14 @@ const criticalWarningTypes = [
3030
'unknownMacro'
3131
];
3232

33+
const pathVariableArgs = [
34+
'--project',
35+
'--addon',
36+
'--suppressions-list',
37+
'--include',
38+
'--rule-file',
39+
];
40+
3341
function parseSeverity(str: string): vscode.DiagnosticSeverity {
3442
const lower = str.toLowerCase();
3543
if (lower.includes("error")) {
@@ -187,7 +195,9 @@ async function runCppcheckOnFileXML(
187195

188196
// Resolve paths for arguments where applicable
189197
const argsParsed = processedArgs.split(" ").map((arg) => {
190-
if (arg.startsWith('--project')) {
198+
const isPathArgument = pathVariableArgs.some(a => arg.startsWith(a));
199+
// Some arguments such as addon may be either a path or the name of a built in addon
200+
if (isPathArgument && looksLikePath(arg)) {
191201
const splitArg = arg.split('=');
192202
return `${splitArg[0]}=${resolvePath(splitArg[1])}`;
193203
}

src/util/path.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@ import * as path from "path";
22
import * as os from "os";
33
import * as vscode from 'vscode';
44

5+
export function looksLikePath(arg: string): boolean {
6+
if (
7+
arg.includes('/')
8+
|| arg.includes('\\')
9+
|| arg.startsWith('.')
10+
|| /\.[^/\\]+$/.test(arg) // filename with extension
11+
) {
12+
return true;
13+
}
14+
return false;
15+
}
16+
517
export function findWorkspaceRoot(): string {
618
const folders = vscode.workspace.workspaceFolders;
719
const workspaceRoot = folders && folders.length > 0

0 commit comments

Comments
 (0)