threads / bug / 55151

Bug Report: Multi-line trailers containing empty lines break parsing

Subject: Bug Report: Multi-line trailers containing empty lines break parsing

## tl;dr

12 messages between Feb 15, 2021 and Mar 26, 2021.

replies: 11people: 5as markdown or json

Matthias Buehlmann· Feb 15, 2021, 21:54 UTC · lore

Thank you for filling out a Git bug report! Please answer the following questions to help us understand your issue.

What did you do before the bug happened? (Steps to reproduce your issue)
    create a file containing multiline trailer:
    $ echo "Test" > test.txt
    $ git interpret-trailers --where end --if-exists addIfDifferent
--trailer "SingleLineTrailer: This is a single line trailer"
--in-place test.txt
    $ git interpret-trailers --where end --if-exists addIfDifferent
--trailer "MultiLineTrailer: This is"$'\n a folded multi-line\n
trailer' --in-place test.txt
    parse trailers:
    $ git interpret-trailers --parse test.txt
    SingleLineTrailer: This is a single line trailer
    MultiLineTrailer: This is a folded multi-line trailer
    (so far, all is as expected)
    now, adding multiline trailer containing empty line:
    $ git interpret-trailers --where end --if-exists addIfDifferent
--trailer "MultiLineTrailer: This is"$'\n a folded multi-line\n
trailer which\n \n contains an\n empty line' --in-place test.txt
    parse trailers again:
    $ git interpret-trailers --parse test.txt
What did you expect to happen? (Expected behavior)
I would expect the following output:
    $ git interpret-trailers --parse test.txt
    SingleLineTrailer: This is a single line trailer
    MultiLineTrailer: This is a folded multi-line trailer
    MultiLineTrailer: This is a folded multi-line trailer which
contains an empty line
What happened instead? (Actual behavior)
    no output is generated, but exit code is nevertheless 0:
    $ git interpret-trailers --parse test.txt
    $ echo $?
    0
What's different between what you expected and what actually happened?
    I would expect either to get an output or the call to exit non-zero
Anything else you want to add:
    According to my interpretation of the documentation of git
intepret-trailers, empty lines should be supported if properly folded,
in the same way as for example the PGP signature added to the commit
header contains a (properly folded) empty line

Please review the rest of the bug report below. You can delete any lines you don't wish to share.

[System Info] git version: git version 2.30.0.windows.2 cpu: x86_64 built from commit: f8cbc844b81bf6b9e72178bbe891a86c8bf5e9e7 sizeof-long: 4 sizeof-size_t: 8 shell-path: /bin/sh uname: Windows 10.0 18363 compiler info: gnuc: 10.2 libc info: no libc information available $SHELL (typically, interactive shell): C:\Program Files\Git\usr\bin\bash.exe

[Enabled Hooks] post-commit

Junio C Hamano· Feb 16, 2021, 02:29 UTC · re: Matthias Buehlmann · lore

Re: Bug Report: Multi-line trailers containing empty lines break parsing

Matthias Buehlmann <Matthias.Buehlmann@mabulous.com> writes:
> Thank you for filling out a Git bug report!
> Please answer the following questions to help us understand your issue.
Thanks; let's ping our resident trailers expert ;-)

I somehow thought that a trailer is always a single-line thing, without funky line-folding that we have to deal with when we are dealing with e-mail headers.

Show 79 quoted lines
> What did you do before the bug happened? (Steps to reproduce your issue)
>
>     create a file containing multiline trailer:
>
>     $ echo "Test" > test.txt
>     $ git interpret-trailers --where end --if-exists addIfDifferent
> --trailer "SingleLineTrailer: This is a single line trailer"
> --in-place test.txt
>     $ git interpret-trailers --where end --if-exists addIfDifferent
> --trailer "MultiLineTrailer: This is"$'\n a folded multi-line\n
> trailer' --in-place test.txt
>
>     parse trailers:
>
>     $ git interpret-trailers --parse test.txt
>     SingleLineTrailer: This is a single line trailer
>     MultiLineTrailer: This is a folded multi-line trailer
>
>     (so far, all is as expected)
>
>     now, adding multiline trailer containing empty line:
>
>     $ git interpret-trailers --where end --if-exists addIfDifferent
> --trailer "MultiLineTrailer: This is"$'\n a folded multi-line\n
> trailer which\n \n contains an\n empty line' --in-place test.txt
>
>     parse trailers again:
>
>     $ git interpret-trailers --parse test.txt
>
> What did you expect to happen? (Expected behavior)
>
> I would expect the following output:
>
>     $ git interpret-trailers --parse test.txt
>     SingleLineTrailer: This is a single line trailer
>     MultiLineTrailer: This is a folded multi-line trailer
>     MultiLineTrailer: This is a folded multi-line trailer which
> contains an empty line
>
> What happened instead? (Actual behavior)
>
>     no output is generated, but exit code is nevertheless 0:
>
>     $ git interpret-trailers --parse test.txt
>     $ echo $?
>     0
>
> What's different between what you expected and what actually happened?
>
>     I would expect either to get an output or the call to exit non-zero
>
> Anything else you want to add:
>
>     According to my interpretation of the documentation of git
> intepret-trailers, empty lines should be supported if properly folded,
> in the same way as for example the PGP signature added to the commit
> header contains a (properly folded) empty line
>
> Please review the rest of the bug report below.
> You can delete any lines you don't wish to share.
>
>
> [System Info]
> git version:
> git version 2.30.0.windows.2
> cpu: x86_64
> built from commit: f8cbc844b81bf6b9e72178bbe891a86c8bf5e9e7
> sizeof-long: 4
> sizeof-size_t: 8
> shell-path: /bin/sh
> uname: Windows 10.0 18363
> compiler info: gnuc: 10.2
> libc info: no libc information available
> $SHELL (typically, interactive shell): C:\Program Files\Git\usr\bin\bash.exe
>
>
> [Enabled Hooks]
> post-commit
Taylor Blau· Feb 16, 2021, 18:07 UTC · re: Junio C Hamano · lore

Re: Bug Report: Multi-line trailers containing empty lines break parsing

On Mon, Feb 15, 2021 at 06:29:55PM -0800, Junio C Hamano wrote:
Show 6 quoted lines
> Matthias Buehlmann <Matthias.Buehlmann@mabulous.com> writes:
>
> > Thank you for filling out a Git bug report!
> > Please answer the following questions to help us understand your issue.
>
> Thanks; let's ping our resident trailers expert ;-)
I'm not Christian, but hopefully I'm an OK substitute :).

I originally thought that this was an ambiguous test, since you could reasonably say the trailers begin after the blank line in the second "MultiLineTrailer" block. In that case, neither of the following lines look like a trailer, so 'git interpret-trailers' could reasonably print nothing.

But I was being tricked, since I looked at "test.txt" in my editor, which automatically replaces blank lines (zero or more space characters ending in a newline) with a single newline. In fact, this isn't ambiguous at all, since the blank lines are continuations (they are a single space character and then a newline):

		00000090  65 64 20 6d 75 6c 74 69  2d 6c 69 6e 65 0a 20 74  |ed multi-line. t|
		000000a0  72 61 69 6c 65 72 20 77  68 69 63 68 0a 20 0a 20  |railer which. . |
(see the repeated '0a 20' space + newline pair after "which").

I think that this is a legitimate bug in 'interpret-trailers' that it doesn't know to continue multi-line trailers that have empty lines in them.

I thought that this might have dated back to 022349c3b0 (trailer: avoid unnecessary splitting on lines, 2016-11-02), but checking out that commit's first parent shows the bug (albeit without --parse, which didn't exist then).

Anyway, I'm pretty sure the problem is that trailer.c:find_trailer_start() doesn't disambiguate between a blank line and one that contains only space characters.

This patch might do the trick:
--- 8< ---
Subject: [PATCH] trailer.c: handle empty continuation lines

In a multi-line trailer, it is possible to have a continuation line which contains at least one space character, terminating in a newline.

In this case, the trailer should continue across the blank continuation line, but 'trailer.c:find_trailer_start()' handles this case incorrectly.

When it encounters a blank line, find_trailer_start() assumes that the trailers must begin on the line following the one it's looking at. But this isn't the case if the line is a non-empty continuation, in which the line may be part of a trailer.

Fix this by only considering a blank line which has exactly zero space characters before the LF as delimiting the start of trailers.

Reported-by: Matthias Buehlmann <Matthias.Buehlmann@mabulous.com>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
---
 t/t7513-interpret-trailers.sh | 23 +++++++++++++++++++++++
 trailer.c                     |  2 +-
 2 files changed, 24 insertions(+), 1 deletion(-)
diff --git a/t/t7513-interpret-trailers.sh b/t/t7513-interpret-trailers.sh
index 6602790b5f..af602ff329 100755
--- a/t/t7513-interpret-trailers.sh
+++ b/t/t7513-interpret-trailers.sh
@@ -1476,4 +1476,27 @@ test_expect_success 'suppress --- handling' '
 	test_cmp expected actual
 '

+test_expect_success 'handling of empty continuations lines' '
+	tr _ " " >input <<-\EOF &&
+	subject
+
+	body
+
+	trailer: single
+	multi: one
+	_two
+	multi: one
+	_
+	_two
+	_three
+	EOF
+	cat >expect <<-\EOF &&
+	trailer: single
+	multi: one two
+	multi: one two three
+	EOF
+	git interpret-trailers --parse <input >actual &&
+	test_cmp expect actual
+'
+
 test_done
diff --git a/trailer.c b/trailer.c
index 249ed618ed..7ca7200aec 100644
--- a/trailer.c
+++ b/trailer.c
@@ -846,7 +846,7 @@ static size_t find_trailer_start(const char *buf, size_t len)
 			possible_continuation_lines = 0;
 			continue;
 		}
-		if (is_blank_line(bol)) {
+		if (is_blank_line(bol) && *bol == '\n') {
 			if (only_spaces)
 				continue;
 			non_trailer_lines += possible_continuation_lines;
--
2.30.0.667.g81c0cbc6fd
Junio C Hamano· Feb 16, 2021, 19:39 UTC · re: Taylor Blau · lore

Re: Bug Report: Multi-line trailers containing empty lines break parsing

Taylor Blau <me@ttaylorr.com> writes:
> Anyway, I'm pretty sure the problem is that
> trailer.c:find_trailer_start() doesn't disambiguate between a blank line
> and one that contains only space characters.

I saw that while reviewing another topic the other day and found it a bit strange, but kept it as I thought it was deliberate and the behaviour (i.e. a line with only blanks and a line that is empty are treated the same) was protected with some tests, but looking at your patch below, I guess there is no such test.

Show 7 quoted lines
> When it encounters a blank line, find_trailer_start() assumes that the
> trailers must begin on the line following the one it's looking at. But
> this isn't the case if the line is a non-empty continuation, in which
> the line may be part of a trailer.
>
> Fix this by only considering a blank line which has exactly zero space
> characters before the LF as delimiting the start of trailers.
Hmph...
Show 22 quoted lines
> +test_expect_success 'handling of empty continuations lines' '
> +	tr _ " " >input <<-\EOF &&
> +	subject
> +
> +	body
> +
> +	trailer: single
> +	multi: one
> +	_two
> +	multi: one
> +	_
> +	_two
> +	_three
> +	EOF
> +	cat >expect <<-\EOF &&
> +	trailer: single
> +	multi: one two
> +	multi: one two three
> +	EOF
> +	git interpret-trailers --parse <input >actual &&
> +	test_cmp expect actual
> +'

A few comments (not pointing out bugs, but just sharing observations).

 - if the line before "trailer: single" were not an empty line but a
   line with a single SP on it (which is is_blank_line()), would the
   new logic get confused?
 - if the second "multi:" trailer did not have the funny blank line
   before "_two", the expected output would still be "multi:"
   followed by "one two three", iow, the line after the second
   "multi: one" is a total no-op?  If we added many more " \n" lines
   there, they are all absorbed and ignored?  It somehow feels wrong
Show 15 quoted lines
> diff --git a/trailer.c b/trailer.c
> index 249ed618ed..7ca7200aec 100644
> --- a/trailer.c
> +++ b/trailer.c
> @@ -846,7 +846,7 @@ static size_t find_trailer_start(const char *buf, size_t len)
>  			possible_continuation_lines = 0;
>  			continue;
>  		}
> -		if (is_blank_line(bol)) {
> +		if (is_blank_line(bol) && *bol == '\n') {
>  			if (only_spaces)
>  				continue;
>  			non_trailer_lines += possible_continuation_lines;
> --
> 2.30.0.667.g81c0cbc6fd
Taylor Blau· Feb 16, 2021, 19:47 UTC · re: Junio C Hamano · lore

Re: Bug Report: Multi-line trailers containing empty lines break parsing

On Tue, Feb 16, 2021 at 11:39:00AM -0800, Junio C Hamano wrote:
Show 6 quoted lines
> A few comments (not pointing out bugs, but just sharing
> observations).
>
>  - if the line before "trailer: single" were not an empty line but a
>    line with a single SP on it (which is is_blank_line()), would the
>    new logic get confused?

Oof. That breaks the new test, but it makes me worried about whether this can be parsed without ambiguity. I think not, but here I'd defer to Christian or Jonathan Tan.

Show 5 quoted lines
>  - if the second "multi:" trailer did not have the funny blank line
>    before "_two", the expected output would still be "multi:"
>    followed by "one two three", iow, the line after the second
>    "multi: one" is a total no-op?  If we added many more " \n" lines
>    there, they are all absorbed and ignored?  It somehow feels wrong

That's definitely the outcome of this patch, but I agree it feels wrong. I'm not sure that we define the behavior that strictly in git-interpret-trailers(1), so we have some wiggle room, I guess.

Thanks, Taylor

Christian Couder· Mar 23, 2021, 15:17 UTC · re: Taylor Blau · lore

Re: Bug Report: Multi-line trailers containing empty lines break parsing

On Tue, Feb 16, 2021 at 8:47 PM Taylor Blau <me@ttaylorr.com> wrote:
Show 12 quoted lines
>
> On Tue, Feb 16, 2021 at 11:39:00AM -0800, Junio C Hamano wrote:
> > A few comments (not pointing out bugs, but just sharing
> > observations).
> >
> >  - if the line before "trailer: single" were not an empty line but a
> >    line with a single SP on it (which is is_blank_line()), would the
> >    new logic get confused?
>
> Oof. That breaks the new test, but it makes me worried about whether
> this can be parsed without ambiguity. I think not, but here I'd defer to
> Christian or Jonathan Tan.

Sorry for the late answer on this. It looks like this fell into my email reading cracks.

My opinion, when I worked on this, was that it's very difficult to avoid ambiguity, so it's better if `git interpret-trailers` is strict by default, which could be relaxed later in special cases where there is not much risk of ambiguity.

It's especially ambiguous because many commit message subjects or even bodies can be of the form "area: change" which can look like a trailer. And some people might want to process whole commit messages, while others might want to process templates that might contain only trailers.

So I thought that blank lines should not appear in the trailers. And if any appears, it means that the trailers should start after the last blank line. This might actually have been already relaxed a bit.

Show 9 quoted lines
> >  - if the second "multi:" trailer did not have the funny blank line
> >    before "_two", the expected output would still be "multi:"
> >    followed by "one two three", iow, the line after the second
> >    "multi: one" is a total no-op?  If we added many more " \n" lines
> >    there, they are all absorbed and ignored?  It somehow feels wrong
>
> That's definitely the outcome of this patch, but I agree it feels wrong.
> I'm not sure that we define the behavior that strictly in
> git-interpret-trailers(1), so we have some wiggle room, I guess.

Any patch to relax how blank lines and other aspects of trailers parsing in my opinion should come with some documentation change to explain what we now accept and what we don't accept, and also tests to enforce that.

Junio C Hamano· Mar 23, 2021, 17:39 UTC · re: Christian Couder · lore

Re: Bug Report: Multi-line trailers containing empty lines break parsing

Christian Couder <christian.couder@gmail.com> writes:
> So I thought that blank lines should not appear in the trailers. And
> if any appears, it means that the trailers should start after the last
> blank line.
I think that is a good principle to stick to.
Show 14 quoted lines
>> >  - if the second "multi:" trailer did not have the funny blank line
>> >    before "_two", the expected output would still be "multi:"
>> >    followed by "one two three", iow, the line after the second
>> >    "multi: one" is a total no-op?  If we added many more " \n" lines
>> >    there, they are all absorbed and ignored?  It somehow feels wrong
>>
>> That's definitely the outcome of this patch, but I agree it feels wrong.
>> I'm not sure that we define the behavior that strictly in
>> git-interpret-trailers(1), so we have some wiggle room, I guess.
>
> Any patch to relax how blank lines and other aspects of trailers
> parsing in my opinion should come with some documentation change to
> explain what we now accept and what we don't accept, and also tests to
> enforce that.

OK. But do we document clearly what we accept and we don't before any change?

Christian Couder· Mar 25, 2021, 07:53 UTC · re: Junio C Hamano · lore

Re: Bug Report: Multi-line trailers containing empty lines break parsing

On Tue, Mar 23, 2021 at 6:39 PM Junio C Hamano <gitster@pobox.com> wrote:
Show 26 quoted lines
>
> Christian Couder <christian.couder@gmail.com> writes:
>
> > So I thought that blank lines should not appear in the trailers. And
> > if any appears, it means that the trailers should start after the last
> > blank line.
>
> I think that is a good principle to stick to.
>
> >> >  - if the second "multi:" trailer did not have the funny blank line
> >> >    before "_two", the expected output would still be "multi:"
> >> >    followed by "one two three", iow, the line after the second
> >> >    "multi: one" is a total no-op?  If we added many more " \n" lines
> >> >    there, they are all absorbed and ignored?  It somehow feels wrong
> >>
> >> That's definitely the outcome of this patch, but I agree it feels wrong.
> >> I'm not sure that we define the behavior that strictly in
> >> git-interpret-trailers(1), so we have some wiggle room, I guess.
> >
> > Any patch to relax how blank lines and other aspects of trailers
> > parsing in my opinion should come with some documentation change to
> > explain what we now accept and what we don't accept, and also tests to
> > enforce that.
>
> OK.  But do we document clearly what we accept and we don't before
> any change?
Maybe it's not enough, but the doc already has the following:

------ Existing trailers are extracted from the input message by looking for a group of one or more lines that (i) is all trailers, or (ii) contains at least one Git-generated or user-configured trailer and consists of at least 25% trailers. The group must be preceded by one or more empty (or whitespace-only) lines. The group must either be at the end of the message or be the last non-whitespace lines before a line that starts with '---' (followed by a space or the end of the line). Such three minus signs start the patch part of the message. See also `--no-divider` below.

When reading trailers, there can be whitespaces after the token, the separator and the value. There can also be whitespaces inside the token and the value. The value may be split over multiple lines with each subsequent line starting with whitespace, like the "folding" in RFC 822. ------

ZheNing Hu· Mar 25, 2021, 09:33 UTC · re: Christian Couder · lore

Re: Bug Report: Multi-line trailers containing empty lines break parsing

Christian Couder <christian.couder@gmail.com> 于2021年3月25日周四 下午3:54写道:
Show 47 quoted lines
>
> On Tue, Mar 23, 2021 at 6:39 PM Junio C Hamano <gitster@pobox.com> wrote:
> >
> > Christian Couder <christian.couder@gmail.com> writes:
> >
> > > So I thought that blank lines should not appear in the trailers. And
> > > if any appears, it means that the trailers should start after the last
> > > blank line.
> >
> > I think that is a good principle to stick to.
> >
> > >> >  - if the second "multi:" trailer did not have the funny blank line
> > >> >    before "_two", the expected output would still be "multi:"
> > >> >    followed by "one two three", iow, the line after the second
> > >> >    "multi: one" is a total no-op?  If we added many more " \n" lines
> > >> >    there, they are all absorbed and ignored?  It somehow feels wrong
> > >>
> > >> That's definitely the outcome of this patch, but I agree it feels wrong.
> > >> I'm not sure that we define the behavior that strictly in
> > >> git-interpret-trailers(1), so we have some wiggle room, I guess.
> > >
> > > Any patch to relax how blank lines and other aspects of trailers
> > > parsing in my opinion should come with some documentation change to
> > > explain what we now accept and what we don't accept, and also tests to
> > > enforce that.
> >
> > OK.  But do we document clearly what we accept and we don't before
> > any change?
>
> Maybe it's not enough, but the doc already has the following:
>
> ------
> Existing trailers are extracted from the input message by looking for
> a group of one or more lines that (i) is all trailers, or (ii) contains at
> least one Git-generated or user-configured trailer and consists of at
> least 25% trailers.
> The group must be preceded by one or more empty (or whitespace-only) lines.
> The group must either be at the end of the message or be the last
> non-whitespace lines before a line that starts with '---' (followed by a
> space or the end of the line). Such three minus signs start the patch
> part of the message. See also `--no-divider` below.
>
> When reading trailers, there can be whitespaces after the
> token, the separator and the value. There can also be whitespaces
> inside the token and the value. The value may be split over multiple lines with
> each subsequent line starting with whitespace, like the "folding" in RFC 822.
> ------
Maybe I don't have enough right to speak on this issue, but I always think that
 the empty line is intentional by the designer, especially when I test it.
Junio C Hamano· Mar 25, 2021, 18:16 UTC · re: ZheNing Hu · lore

Re: Bug Report: Multi-line trailers containing empty lines break parsing

ZheNing Hu <adlternative@gmail.com> writes:
Show 24 quoted lines
> Christian Couder <christian.couder@gmail.com> 于2021年3月25日周四 下午3:54写道:
>>
>> Maybe it's not enough, but the doc already has the following:
>>
>> ------
>> Existing trailers are extracted from the input message by looking for
>> a group of one or more lines that (i) is all trailers, or (ii) contains at
>> least one Git-generated or user-configured trailer and consists of at
>> least 25% trailers.
>> The group must be preceded by one or more empty (or whitespace-only) lines.
>> The group must either be at the end of the message or be the last
>> non-whitespace lines before a line that starts with '---' (followed by a
>> space or the end of the line). Such three minus signs start the patch
>> part of the message. See also `--no-divider` below.
>>
>> When reading trailers, there can be whitespaces after the
>> token, the separator and the value. There can also be whitespaces
>> inside the token and the value. The value may be split over multiple lines with
>> each subsequent line starting with whitespace, like the "folding" in RFC 822.
>> ------
>
>
> Maybe I don't have enough right to speak on this issue, but I always think that
>  the empty line is intentional by the designer, especially when I test it.

People like you, who is relatively new to the system and the list, are valuable source of information for us to learn where in the current system and documentation we have room to improve and clarify. You do have right, and we welcome your input.

Care to clarify what you mean by "the empty line is intentional by the designer"? The designer of the current "trailer" intended to make the "last paragraph" (where "paragraph" is defined as a run of lines without an empty line in it, so that one or more continguous empty lines separate "paragraphs") where the trailers sit in the log message. Is that what you mean? Or something else?

ZheNing Hu· Mar 26, 2021, 10:25 UTC · re: Junio C Hamano · lore

Re: Bug Report: Multi-line trailers containing empty lines break parsing

Junio C Hamano <gitster@pobox.com> 于2021年3月26日周五 上午2:16写道:
Show 33 quoted lines
>
> ZheNing Hu <adlternative@gmail.com> writes:
>
> > Christian Couder <christian.couder@gmail.com> 于2021年3月25日周四 下午3:54写道:
> >>
> >> Maybe it's not enough, but the doc already has the following:
> >>
> >> ------
> >> Existing trailers are extracted from the input message by looking for
> >> a group of one or more lines that (i) is all trailers, or (ii) contains at
> >> least one Git-generated or user-configured trailer and consists of at
> >> least 25% trailers.
> >> The group must be preceded by one or more empty (or whitespace-only) lines.
> >> The group must either be at the end of the message or be the last
> >> non-whitespace lines before a line that starts with '---' (followed by a
> >> space or the end of the line). Such three minus signs start the patch
> >> part of the message. See also `--no-divider` below.
> >>
> >> When reading trailers, there can be whitespaces after the
> >> token, the separator and the value. There can also be whitespaces
> >> inside the token and the value. The value may be split over multiple lines with
> >> each subsequent line starting with whitespace, like the "folding" in RFC 822.
> >> ------
> >
> >
> > Maybe I don't have enough right to speak on this issue, but I always think that
> >  the empty line is intentional by the designer, especially when I test it.
>
> People like you, who is relatively new to the system and the list,
> are valuable source of information for us to learn where in the
> current system and documentation we have room to improve and
> clarify.  You do have right, and we welcome your input.
>
Thanks:)
Show 6 quoted lines
> Care to clarify what you mean by "the empty line is intentional by
> the designer"?  The designer of the current "trailer" intended to
> make the "last paragraph" (where "paragraph" is defined as a run of
> lines without an empty line in it, so that one or more continguous
> empty lines separate "paragraphs") where the trailers sit in the log
> message.  Is that what you mean?  Or something else?

Emmm, I mean generally speaking, the entire commit infomations is divided into three paragraphs: "subject"/"message"/"trailers".

When we use `--parse` to get those trailers, normally it can indeed be obtained, But if in the middle of the trailers have a extra empty lines or lines with only whitespaces, All trailers before the blank line will be discarded, I think it is acceptable.Because It seems that the previous content belongs to the message section.

Like this: ------ (subject)

First paragraph: hello world

Second paragraph: what happen if some thing like

this: Use git to commit code to git
Signed-off-by: CoCo <cc@gg.com>
Deleted-by: ADL <a@gg.com>
-----

"this: Use git to commit code to git" seem like a trailer, but it's user's message.

So I think the purpose of these blank lines is to separate the three parts of the commit information. It is normal for the blank lines inside trailers to cause ambiguity.

Please correct me if I what I said is wrong. -- ZheNing Hu

Junio C Hamano· Mar 25, 2021, 18:08 UTC · re: Christian Couder · lore

Re: Bug Report: Multi-line trailers containing empty lines break parsing

Christian Couder <christian.couder@gmail.com> writes:
Show 9 quoted lines
>> > Any patch to relax how blank lines and other aspects of trailers
>> > parsing in my opinion should come with some documentation change to
>> > explain what we now accept and what we don't accept, and also tests to
>> > enforce that.
>>
>> OK.  But do we document clearly what we accept and we don't before
>> any change?
>
> Maybe it's not enough, but the doc already has the following:
OK.

The next step is to find out if there is anything unclear in the description of the current behaviour in that paragraph that may have resulted in the report of the "bug" that turned out to be a non-bug.

Show 16 quoted lines
> ------
> Existing trailers are extracted from the input message by looking for
> a group of one or more lines that (i) is all trailers, or (ii) contains at
> least one Git-generated or user-configured trailer and consists of at
> least 25% trailers.
> The group must be preceded by one or more empty (or whitespace-only) lines.
> The group must either be at the end of the message or be the last
> non-whitespace lines before a line that starts with '---' (followed by a
> space or the end of the line). Such three minus signs start the patch
> part of the message. See also `--no-divider` below.
>
> When reading trailers, there can be whitespaces after the
> token, the separator and the value. There can also be whitespaces
> inside the token and the value. The value may be split over multiple lines with
> each subsequent line starting with whitespace, like the "folding" in RFC 822.
> ------
Thanks.

← back to recent threads