Merge branch 'jk/mailinfo-iterative-unquote-comment'

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
This commit is contained in:
Junio C Hamano 2023-12-27 14:52:26 -08:00
commit 9df9e3770a
3 changed files with 8 additions and 4 deletions

View file

@ -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) static const char *unquote_comment(struct strbuf *outbuf, const char *in)
{ {
int take_next_literally = 0; int take_next_literally = 0;
int depth = 1;
strbuf_addch(outbuf, '('); strbuf_addch(outbuf, '(');
@ -72,11 +73,14 @@ static const char *unquote_comment(struct strbuf *outbuf, const char *in)
take_next_literally = 1; take_next_literally = 1;
continue; continue;
case '(': case '(':
in = unquote_comment(outbuf, in); strbuf_addch(outbuf, '(');
depth++;
continue; continue;
case ')': case ')':
strbuf_addch(outbuf, ')'); strbuf_addch(outbuf, ')');
return in; if (!--depth)
return in;
continue;
} }
} }

View file

@ -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: somebody@example.com Email: somebody@example.com
Subject: testing comments Subject: testing comments
Date: Sun, 25 May 2008 00:38:18 -0700 Date: Sun, 25 May 2008 00:38:18 -0700

View file

@ -1,5 +1,5 @@
From 1234567890123456789012345678901234567890 Mon Sep 17 00:00:00 2001 From 1234567890123456789012345678901234567890 Mon Sep 17 00:00:00 2001
From: "A U Thor" <somebody@example.com> (this is \(really\) a comment (honestly)) From: (this is \(really\) a "comment" (honestly)) "A U Thor" <somebody@example.com>
Date: Sun, 25 May 2008 00:38:18 -0700 Date: Sun, 25 May 2008 00:38:18 -0700
Subject: [PATCH] testing comments Subject: [PATCH] testing comments