Skip to content

Commit 7b8f598

Browse files
committed
Sanitize filepath
1 parent dbd5bb7 commit 7b8f598

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/__fixtures__/postprocessArguments.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const postprocessArguments = [
3232
},
3333
],
3434
],
35-
"/mock-filename.js",
35+
`/mock filename with quotes ", semicolons ; and spaces.js`,
3636
] as [Linter.LintMessage[][], string];
3737

3838
export { postprocessArguments };

src/git.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@ import * as child_process from "child_process";
22
import * as path from "path";
33
import { Range } from "./Range";
44

5+
const sanitizeFilePath = (filePath: string) =>
6+
JSON.stringify(path.resolve(filePath));
7+
58
const getDiffForFile = (filePath: string, staged = false): string =>
69
child_process
710
.execSync(
811
`git diff --diff-filter=ACM --unified=0 HEAD ${
912
staged ? " --staged" : ""
10-
} -- ${path.resolve(filePath)}`
13+
} -- ${sanitizeFilePath(filePath)}`
1114
)
1215
.toString();
1316

0 commit comments

Comments
 (0)