mirror of
https://github.com/affaan-m/ECC.git
synced 2026-11-08 00:55:55 +00:00
fix(hooks): decode the escapes that Bash removes in a double-quoted commit message
In double quotes, Bash drops the backslash before $, `, ", \ and a newline, so git receives fix: say "hello" for -m "fix: say \"hello\"". The check kept the backslashes, so an escaped backslash before a newline counted twice. These escapes are now decoded, and a backslash before any other character stays. The test that pinned the escaped quotes now expects the message git records.
This commit is contained in:
2 files changed
+8
-5
No files matched your search
@@ -204,8 +204,9 @@ function validateCommitMessage(command) {
|
||||
const heredoc = messageMatch[1]?.startsWith('$(')
|
||||
? heredocBody(command.slice(messageMatch.index + messageMatch[0].indexOf('"') + 1))
|
||||
: null;
|
||||
// In double quotes, Bash drops a backslash-newline, a line continuation
|
||||
const doubleQuoted = messageMatch[1]?.replace(/\\(\r?\n|[\s\S])/g, (escape, next) => (next.endsWith('\n') ? '' : escape));
|
||||
// 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 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.
|
||||
|
||||
Reference in new issue
Block a user