Skip to content

Commit

Permalink
Merge branch 'jk/mailinfo-iterative-unquote-comment'
Browse files Browse the repository at this point in the history
The code to parse the From e-mail header has been updated to avoid
recursion.

* jk/mailinfo-iterative-unquote-comment:
  mailinfo: avoid recursion when unquoting From headers
  t5100: make rfc822 comment test more careful
  • Loading branch information
gitster committed Dec 27, 2023
2 parents f6a129c + dee1829 commit 9df9e37
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions mailinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ static void parse_bogus_from(struct mailinfo *mi, const struct strbuf *line)
static const char *unquote_comment(struct strbuf *outbuf, const char *in)
{
int take_next_literally = 0;
int depth = 1;

strbuf_addch(outbuf, '(');

Expand All @@ -72,11 +73,14 @@ static const char *unquote_comment(struct strbuf *outbuf, const char *in)
take_next_literally = 1;
continue;
case '(':
in = unquote_comment(outbuf, in);
strbuf_addch(outbuf, '(');
depth++;
continue;
case ')':
strbuf_addch(outbuf, ')');
return in;
if (!--depth)
return in;
continue;
}
}

Expand Down
2 changes: 1 addition & 1 deletion t/t5100/comment.expect
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Author: A U Thor (this is (really) a comment (honestly))
Author: (this is (really) a "comment" (honestly)) A U Thor
Email: [email protected]
Subject: testing comments
Date: Sun, 25 May 2008 00:38:18 -0700
Expand Down
2 changes: 1 addition & 1 deletion t/t5100/comment.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
From 1234567890123456789012345678901234567890 Mon Sep 17 00:00:00 2001
From: "A U Thor" <[email protected]> (this is \(really\) a comment (honestly))
From: (this is \(really\) a "comment" (honestly)) "A U Thor" <[email protected]>
Date: Sun, 25 May 2008 00:38:18 -0700
Subject: [PATCH] testing comments

Expand Down

0 comments on commit 9df9e37

Please sign in to comment.