diff options
author | Maxime Roussin-Bélanger <Lorac@users.noreply.github.com> | 2021-03-07 05:13:25 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-07 11:13:25 +0100 |
commit | fb940e699dabea2f27e0fc8835717b409d23c6ae (patch) | |
tree | d44bac65c1b61295560902b12363e6a13163f636 | |
parent | 9d87cc2cbb84a8c4bd02fc014cfa7907d8cc3b35 (diff) |
Fix missing body rules with multiple new lines (#179)
A body could be crafted with multiple new lines and it would bypass
the bodymissing rule
-rw-r--r-- | gitlint/rules.py | 2 | ||||
-rw-r--r-- | gitlint/tests/rules/test_body_rules.py | 10 |
2 files changed, 11 insertions, 1 deletions
diff --git a/gitlint/rules.py b/gitlint/rules.py index 3dc85b7..db21e56 100644 --- a/gitlint/rules.py +++ b/gitlint/rules.py @@ -290,7 +290,7 @@ class BodyMissing(CommitRule): # ignore merges when option tells us to, which may have no body if self.options['ignore-merge-commits'].value and commit.is_merge_commit: return - if len(commit.message.body) < 2: + if len(commit.message.body) < 2 or not ''.join(commit.message.body).strip(): return [RuleViolation(self.id, "Body message is missing", None, 3)] diff --git a/gitlint/tests/rules/test_body_rules.py b/gitlint/tests/rules/test_body_rules.py index 96ae998..a268585 100644 --- a/gitlint/tests/rules/test_body_rules.py +++ b/gitlint/tests/rules/test_body_rules.py @@ -126,6 +126,16 @@ class BodyRuleTests(BaseTestCase): violations = rule.validate(commit) self.assertListEqual(violations, [expected_violation]) + def test_body_missing_multiple_empty_new_lines(self): + rule = rules.BodyMissing() + + # body is too short + expected_violation = rules.RuleViolation("B6", "Body message is missing", None, 3) + + commit = self.gitcommit("Tïtle\n\n\n\n") + violations = rule.validate(commit) + self.assertListEqual(violations, [expected_violation]) + def test_body_missing_merge_commit(self): rule = rules.BodyMissing() |