git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Fix Q-encoded multi-octet-char split in email.

From
Jeff King <peff@peff.net>
Date
Jul 4, 2012, 06:44 UTC
Message-ID
<20120704064450.GA24807@sigill.intra.peff.net>
In-Reply-To
<CAGxub4-9E0W8ZgsPHeTyUyxmPD80LUd7NjSezg5Zt2-nZPBMJA@mail.gmail.com>
On Wed, Jul 04, 2012 at 03:19:31PM +0900, Katsuyama Takeharu wrote:
Show 15 quoted lines
> diff --git a/pretty.c b/pretty.c
> --- a/pretty.c
> +++ b/pretty.c
> @@ -272,6 +272,13 @@ static void add_rfc2047(struct strbuf *sb, const char
> *line, int len,
>      static const int max_length = 78; /* per rfc2822 */
>      int i;
>      int line_len;
> +    int utf8_ctr, use_utf8;
> +    const char *utf8_start;
> +
> +    if (is_encoding_utf8(encoding) && encoding != NULL)
> +        use_utf8 = 1;
> +    else
> +        use_utf8 = 0;

I think you can drop the "encoding != NULL" here. If we don't have an explicit encoding, git always assumes utf8 (also, as it happens we never hit this point with a NULL encoding in the current code anyway, though that could in theory change in the future).

Show 6 quoted lines
> > Can we re-use utf8_width here instead of rewriting these rules?
> 
> Yes you can. But there are an issue which utf8_width seems not to return
> correct value.  It returns 3  even if  a provided code has 3 octet utf-8
> char(e.g. 0xE38292).
> I expect it returns 2.

Hmm. I think I may have led you astray. It seems that the return value of utf8_width is not about the byte-width of the character representation, but rather about the intended character-width of the glyph. But since we are encoding the bytes, we care about the former.

So I think you would really want to use pick_one_utf8_char and see how many characters it consumed, like this:

  const char *p = &line[i];
  pick_one_utf8_char(&p, NULL);
  if (!p) /* not valid utf8, just assume single byte */
          utf8_ctr = 1;
  else
          utf8_ctr = p - &line[i];
-Peff
Previous: Erik Faye-LundNext: Junio C Hamano
Message 4 of 8 in “Fix Q-encoded multi-octet-char split in email.”
  1. Fix Q-encoded multi-octet-char split in email.katsu, Jul 3, 2012
  2. Jeff KingJul 3, 2012
  3. Erik Faye-LundJul 3, 2012
  4. Jeff KingJul 4, 2012
  5. Junio C HamanoJul 18, 2012
  6. Jeff KingJul 18, 2012
  7. Drew NorthupJul 25, 2012
  8. Junio C HamanoAug 16, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.