@@ -390,6 +390,11 @@ def test_commit_command_with_config_message_length_limit(
390390 100 ,
391391 id = "preserves_line_breaks" ,
392392 ),
393+ pytest .param (
394+ "Line1 is shorter than the limit but has paragraph break\n \n Line2 stays in a separate paragraph" ,
395+ 100 ,
396+ id = "preserves_blank_lines" ,
397+ ),
393398 pytest .param (
394399 "This is a very long line that exceeds 72 characters and should NOT be wrapped when body_length_limit is set to 0" ,
395400 0 ,
@@ -441,3 +446,49 @@ def test_commit_command_body_length_limit(
441446 assert len (body_lines ) == 1 , (
442447 "Body should not be wrapped when body_length_limit is set to 0"
443448 )
449+
450+
451+ @pytest .mark .usefixtures ("staging_is_clean" )
452+ def test_commit_command_body_length_limit_preserves_whitespace_only_lines (
453+ config ,
454+ success_mock : MockType ,
455+ commit_mock ,
456+ mocker : MockFixture ,
457+ ):
458+ """A whitespace-only body line must be kept, not just an empty one.
459+
460+ ``textwrap.wrap`` returns ``[]`` for a whitespace-only string just like it
461+ does for an empty one, so ``_wrap_body`` must special-case it the same
462+ way to avoid silently dropping the paragraph separator. This is asserted
463+ directly (not via ``file_regression``) because the repository's
464+ trailing-whitespace pre-commit hook would strip the whitespace-only line
465+ from any committed fixture file, invalidating the comparison.
466+ """
467+ body = (
468+ "Line1 is shorter than the limit but has paragraph break"
469+ "\n \n "
470+ "Line2 stays in a separate paragraph"
471+ )
472+
473+ mocker .patch (
474+ "questionary.prompt" ,
475+ return_value = {
476+ "prefix" : "feat" ,
477+ "subject" : "add feature" ,
478+ "scope" : "" ,
479+ "is_breaking_change" : False ,
480+ "body" : body ,
481+ "footer" : "" ,
482+ },
483+ )
484+
485+ commands .Commit (config , {"body_length_limit" : 100 })()
486+ success_mock .assert_called_once ()
487+ committed_message = commit_mock .call_args [0 ][0 ]
488+ body_lines = committed_message .split ("\n " )[2 :]
489+
490+ assert body_lines == [
491+ "Line1 is shorter than the limit but has paragraph break" ,
492+ " " ,
493+ "Line2 stays in a separate paragraph" ,
494+ ], "Whitespace-only body line should be preserved, not dropped"
0 commit comments