trailer: forbid leading whitespace in trailers
authorJonathan Tan <jonathantanmy@google.com>
Fri, 21 Oct 2016 17:55:02 +0000 (10:55 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 21 Oct 2016 18:48:35 +0000 (11:48 -0700)
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 <jonathantanmy@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-interpret-trailers.txt
t/t7513-interpret-trailers.sh
trailer.c
index cf4c5ea45f03c59ea20f80531c3f97e5311aa30e..4966b5b104b15fe93af384c4714486f250697b3d 100644 (file)
@@ -55,7 +55,7 @@ The group must either be at the end of the message or be the last
 non-whitespace lines before a line that starts with '---'. Such three
 minus signs start the patch part of the message.
 
 non-whitespace lines before a line that starts with '---'. Such three
 minus signs start the patch part of the message.
 
-When reading trailers, there can be whitespaces before and after the
+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.
 
 token, the separator and the value. There can also be whitespaces
 inside the token and the value.
 
index 003e90f8cf94f0bb2e70b47f59b54bf20c50c777..3d94b3a2f76c9cd04635733bd852df4495987a0f 100755 (executable)
@@ -241,6 +241,21 @@ test_expect_success 'with non-trailer lines only' '
        test_cmp expected actual
 '
 
        test_cmp expected actual
 '
 
+test_expect_success 'line with leading whitespace is not trailer' '
+       q_to_tab >patch <<-\EOF &&
+
+               Qtoken: value
+       EOF
+       q_to_tab >expected <<-\EOF &&
+
+               Qtoken: value
+
+               token: value
+       EOF
+       git interpret-trailers --trailer "token: value" patch >actual &&
+       test_cmp expected actual
+'
+
 test_expect_success 'with config setup' '
        git config trailer.ack.key "Acked-by: " &&
        cat >expected <<-\EOF &&
 test_expect_success 'with config setup' '
        git config trailer.ack.key "Acked-by: " &&
        cat >expected <<-\EOF &&
index 4c5b931bccda907be4919febc9c63c0ce80d642d..84105ac181f657b587d922ecd119ed59303adcd1 100644 (file)
--- a/trailer.c
+++ b/trailer.c
@@ -775,7 +775,7 @@ static int find_trailer_start(struct strbuf **lines, int count)
                }
 
                separator_pos = find_separator(lines[start]->buf);
                }
 
                separator_pos = find_separator(lines[start]->buf);
-               if (separator_pos >= 1) {
+               if (separator_pos >= 1 && !isspace(lines[start]->buf[0])) {
                        struct list_head *pos;
 
                        trailer_lines++;
                        struct list_head *pos;
 
                        trailer_lines++;