blame: tolerate bogus e-mail addresses a bit better
The names and e-mails are sanitized by fmt_ident() when creating commits, so that they do not contain "<" nor ">", and the "committer" and "author" lines in the commit object will always be in the form: ("author" | "committer") name SP "<" email ">" SP timestamp SP zone When parsing the email part out, the current code looks for SP starting from the end of the email part, but the author could obfuscate the address as "author at example dot com". We should instead look for SP followed by "<", to match the logic of the side that formats these lines. Signed-off-by: Josh Stone <jistone@redhat.com> Reviewed-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Josh Stone committed
Apr 21, 2011 at 15:07 UTC
9b01f0038b63ccdf697b2387f4fcd4b03bd249d5
3 files changed
+13
-3
builtin/blame.c
+1
-1
@@ -1377,7 +1377,7 @@ static void get_ac_line(const char *inbuf, const char *what,
1377
timepos = tmp;
1378
1379
*tmp = 0;
1380
- while (person < tmp && *tmp != ' ')
1380
+ while (person < tmp && !(*tmp == ' ' && tmp[1] == '<'))
1381
tmp--;
1382
if (tmp <= person)
1383
return;
t/annotate-tests.sh
+11
-1
@@ -1,5 +1,5 @@
1
# This file isn't used as a test script directly, instead it is
2
-# sourced from t8001-annotate.sh and t8001-blame.sh.
2
+# sourced from t8001-annotate.sh and t8002-blame.sh.
3
4
check_count () {
5
head=
@@ -124,3 +124,13 @@ test_expect_success \
124
test_expect_success \
125
'some edit' \
126
'check_count A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1'
127
+
128
+test_expect_success \
129
+ 'an obfuscated email added' \
130
+ 'sed -e "1i No robots allowed" < file > file.new &&
131
+ mv file.new file &&
132
+ GIT_AUTHOR_NAME="E" GIT_AUTHOR_EMAIL="E at test dot git" git commit -a -m "norobots"'
133
+
134
+test_expect_success \
135
+ 'obfuscated email parsed' \
136
+ 'check_count A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1 E 1'
t/t8002-blame.sh
+1
-1
@@ -8,7 +8,7 @@ PROG='git blame -c'
8
9
PROG='git blame -c -e'
10
test_expect_success 'Blame --show-email works' '
11
- check_count "<A@test.git>" 1 "<B@test.git>" 1 "<B1@test.git>" 1 "<B2@test.git>" 1 "<author@example.com>" 1 "<C@test.git>" 1 "<D@test.git>" 1
11
+ check_count "<A@test.git>" 1 "<B@test.git>" 1 "<B1@test.git>" 1 "<B2@test.git>" 1 "<author@example.com>" 1 "<C@test.git>" 1 "<D@test.git>" 1 "<E at test dot git>" 1
12
'
13
14
test_done