Skip to content

Commit dd558a9

Browse files
committed
Remove double checking
1 parent f6eb247 commit dd558a9

File tree

1 file changed

+2
-13
lines changed

1 file changed

+2
-13
lines changed

src/package.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -423,28 +423,17 @@ function sanitizeCommitMessage(message?: string): string | undefined {
423423
}
424424

425425
// Check for characters that might escape quotes or introduce shell commands.
426-
// Don't allow: ', ", `, $, \ (except for \n)
426+
// Don't allow: ', ", `, $, \ (except for \n which is allowed)
427427
const unsafeRegex = /(?<!\\)\\(?!n)|['"`$]/g;
428428

429429
// Remove any unsafe characters found by the unsafeRegex
430430
const sanitizedMessage = message.replace(unsafeRegex, '');
431431

432-
// Additional check to make sure nothing potentially dangerous is still in the string
433-
if ([`'`, `"`, '`', '$'].some(char => sanitizedMessage.includes(char))) {
434-
throw new Error('Commit message contains potentially dangerous characters after initial sanitization.');
435-
}
436-
437-
for (let index = 0; index < sanitizedMessage.length; index++) {
438-
const char = sanitizedMessage[index];
439-
if (char === '\\' && sanitizedMessage[index + 1] !== 'n') {
440-
throw new Error('Commit message contains potentially dangerous characters after initial sanitization.');
441-
}
442-
}
443-
444432
if (sanitizedMessage.length === 0) {
445433
return undefined;
446434
}
447435

436+
// Add quotes as commit message is passed as a single argument to the shell
448437
return `"${sanitizedMessage}"`;
449438
}
450439

0 commit comments

Comments
 (0)