mirror of
https://github.com/affaan-m/ECC.git
synced 2026-11-07 08:35:54 +00:00
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:
2 files changed
+4
-2
No files matched your search
@@ -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.
|
||||
|
||||
@@ -531,7 +531,9 @@ if (test('drops a line continuation from a double-quoted message, as Bash does',
|
||||
assert.deepStrictEqual(res.issues, []);
|
||||
// An escaped backslash before a newline is one backslash, and the newline stays
|
||||
assert.strictEqual(hook.validateCommitMessage('git commit -m "fix: path C:\\\\\nbody"').message, 'fix: path C:\\\nbody');
|
||||
// Bash removes the backslash only before $ ` " \ and a newline
|
||||
// Bash removes the backslash only before $ ` " \ and a newline; before a CR it stays
|
||||
assert.strictEqual(hook.validateCommitMessage('git commit -m "fix: keep path\\\r\nbody."').message, 'fix: keep path\\\r\nbody.');
|
||||
assert.deepStrictEqual(hook.validateCommitMessage('git commit -m "fix: keep path\\\r\nbody."').issues, []);
|
||||
assert.strictEqual(hook.validateCommitMessage('git commit -m "fix: cost \\$5 in \\d+ steps"').message, 'fix: cost $5 in \\d+ steps');
|
||||
})) passed++; else failed++;
|
||||
|
||||
|
||||
Reference in new issue
Block a user