Skip to content

Commit 02a61be

Browse files
authored
fix: stop truncating the body in presence of dashes (#3476)
* test(parser): add failing test * fix: stop truncating the body in presence of dashes In the current version of commitlint the body is truncated unexpectedly when there is a pattern like '- Something between dashes -' in the commit message body. The reason for this behavior is that in the commit parser package the commitlint uses (conventional-commit-parser[1]), this pattern '- something -' is a special pattern for any arbitrary filed. For example, if you put '-myNote-' in the commit message body, everything that comes after this field will be saved in an arbitrary field called myNote (Or whatever is written between dashes) and you can use it like other fields (header, body, etc.), but I believe we should disable this functionality because, in the commit messages like the one in the bug report that this commit fixes, the user might put stack trace in the commit message body and this way it will be truncated unexpectedly. Fixes #3428 [1] https://github.com/conventional-changelog/conventional-changelog/blob/master/packages/conventional-commits-parser/README.md
1 parent 0a53d97 commit 02a61be

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

@commitlint/parse/src/index.test.ts

+19
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,25 @@ test('registers inline #', async () => {
168168
expect(actual.body).toBe('things #reference');
169169
});
170170

171+
test('keep -side notes- in the body section', async () => {
172+
const header = "type(some/scope): subject"
173+
const body =
174+
"CI on master branch caught this:\n\n" +
175+
"```\n" +
176+
"Unhandled Exception:\n" +
177+
"System.AggregateException: One or more errors occurred. (Some problem when connecting to 'api.mycryptoapi.com/eth')\n\n" +
178+
"--- End of stack trace from previous location where exception was thrown ---\n\n" +
179+
"at GWallet.Backend.FSharpUtil.ReRaise (System.Exception ex) [0x00000] in /Users/runner/work/geewallet/geewallet/src/GWallet.Backend/FSharpUtil.fs:206\n" +
180+
"...\n" +
181+
"```";
182+
183+
const message = header + "\n\n" + body
184+
185+
const actual = await parse(message);
186+
187+
expect(actual.body).toBe(body);
188+
});
189+
171190
test('parses references leading subject', async () => {
172191
const message = '#1 some subject';
173192
const opts = await require('conventional-changelog-angular');

@commitlint/parse/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export default async function parse(
1212
const opts = {
1313
...defaultOpts,
1414
...(parserOpts || {}),
15+
fieldPattern: null
1516
};
1617
const parsed = parser(message, opts) as Commit;
1718
parsed.raw = message;

0 commit comments

Comments
 (0)