fix(hooks): treat only backslash-LF as a line continuation in a commit message

Bash removes a backslash before a newline, but not one before a carriage return. Removing backslash-CRLF joined two lines of the message, and their text was then read as the subject.
This commit is contained in:
L4XB committed 2026-10-23 04:13:06 +02:00
1 parent 71cf7045e8
commit 69cdff28e0
2 files changed
+4 -2

No files matched your search

+1 -1
View File
@@ -206,7 +206,7 @@ function validateCommitMessage(command) {
: null;
// In double quotes, Bash drops the backslash before $ ` " \ and drops a backslash-newline,
// a line continuation, altogether. Before any other character the backslash stays.
const doubleQuoted = messageMatch[1]?.replace(/\\(\r?\n|[$`"\\])/g, (escape, next) => (next.endsWith('\n') ? '' : next));
const doubleQuoted = messageMatch[1]?.replace(/\\([\n$`"\\])/g, (escape, next) => (next === '\n' ? '' : next));
const message = heredoc ?? doubleQuoted ?? messageMatch[2] ?? messageMatch[3];
// The format rules apply to the subject: git drops leading blank lines and trailing
// whitespace, and the first line left is the subject.