From 02a61befad13a348866fce30b15caa67a8360d9c Mon Sep 17 00:00:00 2001 From: Zahra TehraniNasab <50144546+realmarv@users.noreply.github.com> Date: Wed, 4 Jan 2023 12:31:30 +0330 Subject: [PATCH] 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 https://github.com/conventional-changelog/commitlint/issues/3428 [1] https://github.com/conventional-changelog/conventional-changelog/blob/master/packages/conventional-commits-parser/README.md --- @commitlint/parse/src/index.test.ts | 19 +++++++++++++++++++ @commitlint/parse/src/index.ts | 1 + 2 files changed, 20 insertions(+) diff --git a/@commitlint/parse/src/index.test.ts b/@commitlint/parse/src/index.test.ts index 157113c930..cb6baf3e67 100644 --- a/@commitlint/parse/src/index.test.ts +++ b/@commitlint/parse/src/index.test.ts @@ -168,6 +168,25 @@ test('registers inline #', async () => { expect(actual.body).toBe('things #reference'); }); +test('keep -side notes- in the body section', async () => { + const header = "type(some/scope): subject" + const body = + "CI on master branch caught this:\n\n" + + "```\n" + + "Unhandled Exception:\n" + + "System.AggregateException: One or more errors occurred. (Some problem when connecting to 'api.mycryptoapi.com/eth')\n\n" + + "--- End of stack trace from previous location where exception was thrown ---\n\n" + + "at GWallet.Backend.FSharpUtil.ReRaise (System.Exception ex) [0x00000] in /Users/runner/work/geewallet/geewallet/src/GWallet.Backend/FSharpUtil.fs:206\n" + + "...\n" + + "```"; + + const message = header + "\n\n" + body + + const actual = await parse(message); + + expect(actual.body).toBe(body); +}); + test('parses references leading subject', async () => { const message = '#1 some subject'; const opts = await require('conventional-changelog-angular'); diff --git a/@commitlint/parse/src/index.ts b/@commitlint/parse/src/index.ts index 3f90e8a4f6..5037173589 100644 --- a/@commitlint/parse/src/index.ts +++ b/@commitlint/parse/src/index.ts @@ -12,6 +12,7 @@ export default async function parse( const opts = { ...defaultOpts, ...(parserOpts || {}), + fieldPattern: null }; const parsed = parser(message, opts) as Commit; parsed.raw = message;