mailinfo: parse From header more strictly when run from rebase
PATCH 1/1 mailinfo: parse From header more strictly when run from rebase
Given an email address of the form:
[email protected] <[email protected]@11B4E7C6-762E-4CF5-B2EB-3F7BD596981D>
results in "[email protected]" being used as both the name and the address. This is due to an assumption in handle_from() that the first '@' denotes the address portion. The remainder of the string is then assumed to be the name, which is rejected by get_sane_name(), resulting in address being used for the name as well.
I considered making handle_from() smarter by instead looking first for an '@' contained by brackets. But get_sane_name() would still reject "[email protected]" for the name, resulting in "[email protected]@11B4E7C6-762E-4CF5-B2EB-3F7BD596981D" being used for both the name and the address. Hardly an improvement.
In practice, I've only encountered this issue when rebasing commits that were generated by git svn. So instead of adding more heuristics to handle_from(), just make it stricter when run from rebase.
We use undocumented --no-inbody-headers to know when we're running from rebase and then assume the address is of the form:
name <email>
in which case email is extracted purely by brackets and name is trimmed only for whitespace.
--- builtin/mailinfo.c | 15 ++++++++++++--- t/t5100-mailinfo.sh | 2 +- t/t5100/0017 | 17 +++++++++++++++++ t/t5100/info0017 | 5 +++++ t/t5100/info0017--no-inbody-headers | 5 +++++ t/t5100/patch0017 | 12 ++++++++++++ t/t5100/patch0017--no-inbody-headers | 12 ++++++++++++ t/t5100/sample.mbox | 17 +++++++++++++++++ 8 files changed, 81 insertions(+), 4 deletions(-) create mode 100644 t/t5100/0017 create mode 100644 t/t5100/info0017 create mode 100644 t/t5100/info0017--no-inbody-headers create mode 100644 t/t5100/msg0017 create mode 100644 t/t5100/msg0017--no-inbody-headers create mode 100644 t/t5100/patch0017 create mode 100644 t/t5100/patch0017--no-inbody-headers
builtin/mailinfo.c +12 -3
@@ -47,7 +47,7 @@ static void get_sane_name(struct strbuf *out, struct strbuf *name, struct strbufstrbuf_addbuf (out, src); } -static void parse_bogus_from (const struct strbuf *line) +static void parse_bracketed_from (const struct strbuf *line,int strict) {/* John Doe <johndoe> */
@@ -71,7 +71,8 @@ static void parse_bogus_from(const struct strbuf *line)strbuf_reset (&name);strbuf_add (&name, line->buf, bra - line->buf);strbuf_trim (&name); -get_sane_name (&name, &name, &email); +if (!strict) +get_sane_name (&name, &name, &email); }static void handle_from (const struct strbuf *from)
@@ -80,12 +81,20 @@ static void handle_from(const struct strbuf *from)size_t el;struct strbuf f; +if (!use_inbody_headers) { +/* we're running from rebase, so we can assume the from header +* is well-formed and use the stricter parse_bracketed_from +*/ +parse_bracketed_from (from,1 ); +return ; + } +strbuf_init (&f, from->len);strbuf_addbuf (&f, from); at =strchr (f.buf,'@' );if (!at) { -parse_bogus_from (from); +parse_bracketed_from (from,0 );return ; }
t/t5100-mailinfo.sh +1 -1
@@ -11,7 +11,7 @@ test_expect_success 'split sample box' \ 'git mailsplit -o. "$TEST_DIRECTORY"/t5100/sample.mbox >last && last=`cat last` && echo total is $last && - test `cat last` = 16' + test `cat last` = 17' check_mailinfo () { mail=$1 opt=$2
t/t5100/0017 new file +17 -0
@@ -0,0 +1,17 @@ +From 9251ac1cdbf624c31ec0a9996f0b38dc7bcdcd60 Mon Sep 17 00:00:00 2001 +From: [email protected] <[email protected]@11B4E7C6-762E-4CF5-B2EB-3F7BD596981D> +Date: Sun, 6 Jun 2010 22:14:37 -0400 +Subject: initial + +--- + hello | 1 + + 1 files changed, 1 insertions(+), 0 deletions(-) + create mode 100644 hello + +diff --git a/hello b/hello +new file mode 100644 +index 0000000..ce01362 +--- /dev/null ++++ b/hello +@@ -0,0 +1 @@ ++hello
t/t5100/info0017 new file +5 -0
@@ -0,0 +1,5 @@ +Author: [email protected] +Email: [email protected] +Subject: initial +Date: Sun, 6 Jun 2010 22:14:37 -0400 +
t/t5100/info0017--no-inbody-headers new file +5 -0
@@ -0,0 +1,5 @@ +Author: [email protected] +Email: [email protected]@11B4E7C6-762E-4CF5-B2EB-3F7BD596981D +Subject: initial +Date: Sun, 6 Jun 2010 22:14:37 -0400 +
t/t5100/msg0017 new file +0 -0
t/t5100/msg0017--no-inbody-headers new file +0 -0
t/t5100/patch0017 new file +12 -0
@@ -0,0 +1,12 @@ +--- + hello | 1 + + 1 files changed, 1 insertions(+), 0 deletions(-) + create mode 100644 hello + +diff --git a/hello b/hello +new file mode 100644 +index 0000000..ce01362 +--- /dev/null ++++ b/hello +@@ -0,0 +1 @@ ++hello
t/t5100/patch0017--no-inbody-headers new file +12 -0
@@ -0,0 +1,12 @@ +--- + hello | 1 + + 1 files changed, 1 insertions(+), 0 deletions(-) + create mode 100644 hello + +diff --git a/hello b/hello +new file mode 100644 +index 0000000..ce01362 +--- /dev/null ++++ b/hello +@@ -0,0 +1 @@ ++hello
t/t5100/sample.mbox +17 -0
@@ -683,3 +683,20 @@ index e69de29..d95f3ad 100644 @@ -0,0 +1 @@ +content +From 9251ac1cdbf624c31ec0a9996f0b38dc7bcdcd60 Mon Sep 17 00:00:00 2001 +From: [email protected] <[email protected]@11B4E7C6-762E-4CF5-B2EB-3F7BD596981D> +Date: Sun, 6 Jun 2010 22:14:37 -0400 +Subject: initial + +--- + hello | 1 + + 1 files changed, 1 insertions(+), 0 deletions(-) + create mode 100644 hello + +diff --git a/hello b/hello +new file mode 100644 +index 0000000..ce01362 +--- /dev/null ++++ b/hello +@@ -0,0 +1 @@ ++hello
Signature · 1 line
1.7.1
Quoted 10 lines · Jay Soffian
Given an email address of the form:
[email protected] <[email protected]@11B4E7C6-762E-4CF5-B2EB-3F7BD596981D>
results in "[email protected]" being used as both the name and the address. This is due to an assumption in
handle_from()that the first '@' denotes the address portion. The remainder of the string is then assumed to be the name, which is rejected byget_sane_name(), resulting in address being used for the name as well.
Sorry, but it is unclear from your message what problem you are trying to solve, what your desired outcome is, and why you think that outcome is desired. The bracketed one shown above does _not_ look like a valid email address, so using
name = "[email protected]"
email = "[email protected]@11B4..."
does not sound like a good thing to do to begin with.
Quoted 18 lines · Junio C Hamano
Quoted 10 lines · Jay Soffian
Given an email address of the form:
[email protected] <[email protected]@11B4E7C6-762E-4CF5-B2EB-3F7BD596981D>
results in "[email protected]" being used as both the name and the address. This is due to an assumption in
handle_from()that the first '@' denotes the address portion. The remainder of the string is then assumed to be the name, which is rejected byget_sane_name(), resulting in address being used for the name as well.Sorry, but it is unclear from your message what problem you are trying to solve, what your desired outcome is, and why you think that outcome is desired. The bracketed one shown above does _not_ look like a valid email address, so using
Quoted 4 lines
name = "[email protected]"
email = "[email protected]@11B4..."does not sound like a good thing to do to begin with.
You left out this part of my commit message:
"In practice, I've only encountered this issue when rebasing commits that were generated by git svn."
Which is exactly what I was doing. I'm rebasing commits from this repo:
http://src.chromium.org/cgi-bin/gitweb.cgi?p=chromium.git
The rebase operation is munging the address and transforming an author of
[email protected] <[email protected]@0039d316-1c4b-4281-b951-d872f2087c98>
into
[email protected] <[email protected]>
Regardless of whether the address is valid or not, rebase shouldn't munge it.
j.
Quoted 10 lines · Jay Soffian
Quoted 9 lines · Junio C Hamano
Sorry, but it is unclear from your message what problem you are trying to solve, what your desired outcome is, and why you think that outcome is desired. The bracketed one shown above does _not_ look like a valid email address, so using
name = "[email protected]"
email = "[email protected]@11B4..."does not sound like a good thing to do to begin with.
In fact, that is an invalid email address (I thought it might be valid per historical source-routed syntax, but I just checked the RFCs and it's not even valid for that). Nonetheless, my goal is that I can rebase a commit without the address (even an invalid one) being munged.
j.