Re: [PATCH] mailinfo: unescape quoted-pair in header fields
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Sep 21, 2016, 16:07 UTC
- Message-ID
- <xmqqtwd9b5ie.fsf@gitster.mtv.corp.google.com>
- In-Reply-To
- <20160920035710.qw2byl3qeqwih7t5@sigill.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 37 quoted lines
> So if that's the case, do we actually need to care if we see any
> parenthesized comments? I think we should just leave comments in place
> either way, so syntactically they are only interesting insofar as we
> replace quoted pairs or not.
>
> IOW, I wonder if:
>
> while ((c = *in++)) {
> switch (c) {
> case '\\':
> if (!*in)
> return 0; /* ignore trailing backslash */
> /* quoted pair */
> strbuf_addch(out, *in++);
> break;
> case '"':
> /*
> * This may be starting or ending a quoted section,
> * but we do not care whether we are in such a section.
> * We _do_ need to remove the quotes, though, as they
> * are syntactic.
> */
> break;
> default:
> /*
> * Anything else is a normal character we keep. These
> * _might_ be violating the RFC if they are magic
> * characters outside of a quoted section, but we'd
> * rather be liberal and pass them through.
> */
> strbuf_addch(out, c);
> break;
> }
> }
>
> would work. I certainly do not mind following the RFC more closely, but
> AFAICT the very simple code above gives a pretty forgiving outcome.The simplicity of the code does look attractive to me. I do not offhand see an obvious case/flaw that this simplified rule would mangle a valid human-readable part.