Skip to content

Commit ba1ffef

Browse files
Escape % on Windows
Not escaping can cause expansion of environment variables. This combined with the fact that variables in Windows are case-insensitive, `%cI%` has the potential to cause a lot of harm, given the fact that `CI=true` is set for virtually every NPM Continuous Integration build.
1 parent 333c592 commit ba1ffef

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/GitInfo.macro.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ const parsedGitLog = (() => {
77
const commit = {};
88
// only the commit message can have multiple lines. Make sure to always add at the end:
99
// The format is specified in https://git-scm.com/docs/git-log#_pretty_formats
10-
const logResult = execSync('git log --format="%D%n%h%n%H%n%cI%n%B" -n 1 HEAD')
10+
let gitCommand = 'git log --format=%D%n%h%n%H%n%cI%n%B -n 1 HEAD';
11+
if (process.platform === 'win32') {
12+
gitCommand = gitCommand.replace(/%/g, '^%'); // need to escape percents in batch
13+
}
14+
15+
const logResult = execSync(gitCommand)
1116
.toString()
1217
.trim()
1318
.split(/\r?\n/);

0 commit comments

Comments
 (0)