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 <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jonathan Tan committed
Oct 21, 2016 at 10:55 UTC
c463a6b28023dd3ad7ad4542147e20c27dbc83d6
3 files changed
+17
-2
Documentation/git-interpret-trailers.txt
+1
-1
@@ -55,7 +55,7 @@ The group must either be at the end of the message or be the last
55
non-whitespace lines before a line that starts with '---'. Such three
56
minus signs start the patch part of the message.
57
58
-When reading trailers, there can be whitespaces before and after the
58
+When reading trailers, there can be whitespaces after the
59
token, the separator and the value. There can also be whitespaces
60
inside the token and the value.
61
t/t7513-interpret-trailers.sh
+15
@@ -241,6 +241,21 @@ test_expect_success 'with non-trailer lines only' '
241
test_cmp expected actual
242
'
243
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
+
259
test_expect_success 'with config setup' '
260
git config trailer.ack.key "Acked-by: " &&
261
cat >expected <<-\EOF &&
trailer.c
+1
-1
@@ -775,7 +775,7 @@ static int find_trailer_start(struct strbuf **lines, int count)
775
}
776
777
separator_pos = find_separator(lines[start]->buf);
778
- if (separator_pos >= 1) {
778
+ if (separator_pos >= 1 && !isspace(lines[start]->buf[0])) {
779
struct list_head *pos;
780
781
trailer_lines++;