]> git.ipfire.org Git - thirdparty/git.git/commit - pretty.c
format-patch: RFC 2047 says multi-octet character may not be split
authorKirill Smelkov <kirr@mns.spb.ru>
Thu, 7 Mar 2013 10:55:07 +0000 (14:55 +0400)
committerJunio C Hamano <gitster@pobox.com>
Sat, 9 Mar 2013 19:11:19 +0000 (11:11 -0800)
commit6cd3c0532772749bcf6c4688f34c8ecc65ecb655
treee9cbd620a7e93668a04d87b2c0fd1a2017e2b3d5
parent15999998fbda60552742275570947431b57108ae
format-patch: RFC 2047 says multi-octet character may not be split

Even though an earlier attempt (bafc478..41dd00bad) cleaned
up RFC 2047 encoding, pretty.c::add_rfc2047() still decides
where to split the output line by going through the input
one byte at a time, and potentially splits a character in
the middle.  A subject line may end up showing like this:

     ".... fö?? bar".   (instead of  ".... föö bar".)

if split incorrectly.

RFC 2047, section 5 (3) explicitly forbids such beaviour

    Each 'encoded-word' MUST represent an integral number of
    characters.  A multi-octet character may not be split across
    adjacent 'encoded- word's.

that means that e.g. for

    Subject: .... föö bar

encoding

    Subject: =?UTF-8?q?....=20f=C3=B6=C3=B6?=
     =?UTF-8?q?=20bar?=

is correct, and

    Subject: =?UTF-8?q?....=20f=C3=B6=C3?=      <-- NOTE ö is broken here
     =?UTF-8?q?=B6=20bar?=

is not, because "ö" character UTF-8 encoding C3 B6 is split here across
adjacent encoded words.

To fix the problem, make the loop grab one _character_ at a time and
determine its output length to see where to break the output line.  Note
that this version only knows about UTF-8, but the logic to grab one
character is abstracted out in mbs_chrlen() function to make it possible
to extend it to other encodings with the help of iconv in the future.

Signed-off-by: Kirill Smelkov <kirr@mns.spb.ru>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
pretty.c
t/t4014-format-patch.sh
utf8.c
utf8.h