@@ -395,30 +395,33 @@ export async function versionBump(options: IVersionBumpOptions): Promise<void> {
395
395
}
396
396
}
397
397
398
+
398
399
// call `npm version` to do our dirty work
399
400
const args = [ 'version' , options . version ] ;
400
401
401
- if ( options . commitMessage ) {
402
- // Sanitize commit message due to possible shell injection on windows
403
- const sanitizedCommitMessage = sanitizeCommitMessage ( options . commitMessage ) ;
404
- if ( sanitizedCommitMessage ) {
405
- args . push ( '-m' , sanitizedCommitMessage ) ;
406
- }
402
+ const isWindows = process . platform === 'win32' ;
403
+
404
+ const commitMessage = isWindows ? sanitizeCommitMessage ( options . commitMessage ) : options . commitMessage ;
405
+ if ( commitMessage ) {
406
+ args . push ( '-m' , commitMessage ) ;
407
407
}
408
408
409
409
if ( ! ( options . gitTagVersion ?? true ) ) {
410
410
args . push ( '--no-git-tag-version' ) ;
411
411
}
412
412
413
- const isWindows = process . platform === 'win32' ;
414
413
const { stdout, stderr } = await promisify ( cp . execFile ) ( isWindows ? 'npm.cmd' : 'npm' , args , { cwd, shell : isWindows /* https://nodejs.org/en/blog/vulnerability/april-2024-security-releases-2 */ } ) ;
415
414
if ( ! process . env [ 'VSCE_TESTS' ] ) {
416
415
process . stdout . write ( stdout ) ;
417
416
process . stderr . write ( stderr ) ;
418
417
}
419
418
}
420
419
421
- function sanitizeCommitMessage ( message : string ) : string | undefined {
420
+ function sanitizeCommitMessage ( message ?: string ) : string | undefined {
421
+ if ( ! message ) {
422
+ return undefined ;
423
+ }
424
+
422
425
// Allow alphanumeric, space, common punctuation, newline characters.
423
426
// Specifically check for characters that might escape quotes or introduce shell commands.
424
427
// Newlines are allowed, but backslashes (other than for newlines), backticks, and dollar signs are still checked.
0 commit comments