Re: [PATCH v2 2/2] mailinfo: unescape quoted-pair in header fields
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Sep 19, 2016, 21:24 UTC
- Message-ID
- <xmqqvaxrd1ml.fsf@gitster.mtv.corp.google.com>
- In-Reply-To
- <20160919185440.18234-3-me@ikke.info>
Kevin Daudt <me@ikke.info> writes:
Show 43 quoted lines
> +static void unquote_quoted_string(struct strbuf *line)
> +{
> + const char *in = strbuf_detach(line, NULL);
> + int c, take_next_literally = 0;
> + int found_error = 0;
> +
> + /*
> + * Stores the character that started the escape mode so that we know what
> + * character will stop it
> + */
> + char escape_context = 0;
> +
> + while ((c = *in++) != 0) {
> + if (take_next_literally) {
> + take_next_literally = 0;
> + } else {
> + switch (c) {
> + case '"':
> + if (!escape_context)
> + escape_context = '"';
> + else if (escape_context == '"')
> + escape_context = 0;
> + continue;
> + case '\\':
> + if (escape_context) {
> + take_next_literally = 1;
> + continue;
> + }
> + break;
> + case '(':
> + if (!escape_context)
> + escape_context = '(';
> + break;
> + case ')':
> + if (escape_context == '(')
> + escape_context = 0;
> + break;
> + }
> + }
> +
> + strbuf_addch(line, c);
> + }
> +}The additional comment makes it very clear what is going on.
Is it an event unusual enough that is worth warning() about if we have either take_next_literally or escape_context set to non-NUL upon leaving the loop, I wonder?
Will queue. Thanks.