Skip to content

Commit c463a6b

Browse files
jonathantanmygitster
authored andcommitted
trailer: forbid leading whitespace in trailers
Currently, interpret-trailers allows leading whitespace in trailer lines. This leads to false positives, especially for quoted lines or bullet lists. Forbid leading whitespace in trailers. Signed-off-by: Jonathan Tan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1462450 commit c463a6b

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

Documentation/git-interpret-trailers.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ The group must either be at the end of the message or be the last
5555
non-whitespace lines before a line that starts with '---'. Such three
5656
minus signs start the patch part of the message.
5757

58-
When reading trailers, there can be whitespaces before and after the
58+
When reading trailers, there can be whitespaces after the
5959
token, the separator and the value. There can also be whitespaces
6060
inside the token and the value.
6161

t/t7513-interpret-trailers.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,21 @@ test_expect_success 'with non-trailer lines only' '
241241
test_cmp expected actual
242242
'
243243

244+
test_expect_success 'line with leading whitespace is not trailer' '
245+
q_to_tab >patch <<-\EOF &&
246+
247+
Qtoken: value
248+
EOF
249+
q_to_tab >expected <<-\EOF &&
250+
251+
Qtoken: value
252+
253+
token: value
254+
EOF
255+
git interpret-trailers --trailer "token: value" patch >actual &&
256+
test_cmp expected actual
257+
'
258+
244259
test_expect_success 'with config setup' '
245260
git config trailer.ack.key "Acked-by: " &&
246261
cat >expected <<-\EOF &&

trailer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ static int find_trailer_start(struct strbuf **lines, int count)
775775
}
776776

777777
separator_pos = find_separator(lines[start]->buf);
778-
if (separator_pos >= 1) {
778+
if (separator_pos >= 1 && !isspace(lines[start]->buf[0])) {
779779
struct list_head *pos;
780780

781781
trailer_lines++;

0 commit comments

Comments
 (0)