@@ -34,9 +34,9 @@ test_expect_success 'no encoding header for base case' 'testz="z$E"'-test_expect_failure'UTF-16 refused because of NULs''+test_expect_success'UTF-16 refused because of NULs''echoUTF-16>F&&-gitcommit-a-F"$TEST_DIRECTORY"/t3900/UTF-16.txt+test_must_failgitcommit-a-F"$TEST_DIRECTORY"/t3900/UTF-16.txt'
We rely on ASCII everywhere. We print "\n" directly without conversion
for example. The end result would be a mix of some encoding and ASCII
if they are incompatible. Do not do that.
In theory we could convert everything to utf-8 as intermediate medium,
process process process, then convert final output to the desired
encoding. But that's a lot of work (unless we have a pager-like
converter) with little real use. Users can just pipe everything to
iconv instead.
Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
---
It seems half of the encodings "iconv -l" list does not pass
ascii_superset_encoding() test. I just assume they are either exotic
or duplicate names.
pretty.c | 7 +++++++
utf8.c | 15 +++++++++++++++
utf8.h | 1 +
3 files changed, 23 insertions(+), 0 deletions(-)
@@ -493,12 +493,19 @@ char *logmsg_reencode(const struct commit *commit,constchar*output_encoding){staticconstchar*utf8="UTF-8";+staticconstchar*last_output_encoding=NULL;constchar*use_encoding;char*encoding;char*out;if(!*output_encoding)returnNULL;+if(last_output_encoding!=output_encoding){+if(!ascii_superset_encoding(output_encoding))+die("encoding %s is not a superset of ASCII.",+output_encoding);+last_output_encoding=output_encoding;+}encoding=get_header(commit,"encoding");use_encoding=encoding?encoding:utf8;if(!strcmp(use_encoding,output_encoding))
Return value NULL in this case means "no conversion needed", which is
not quite true when conv == -1.
Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
---
t/t4201-shortlog.sh | 2 +-
utf8.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
@@ -27,7 +27,7 @@ test_expect_success 'setup' 'tr1234"\360\235\204\236")" a1 &&# now fsck up the utf8-gitconfigi18n.commitencodingnon-utf-8&&+gitconfigi18n.commitencodingviscii&&echo4>a1&&gitcommit--quiet-m"$(echo"This is a very, very long first line for the commit message to see if it is wrapped correctly"|
Commit object has its own format, which happens to be in ascii, but
not really subject to re-encoding.
There are only four areas that may be re-encoded: author line,
committer line, mergetag lines and commit body. Encoding of tags
embedded in mergetag lines is not decided by commit encoding, so leave
it out and consider it binary.
Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
---
pretty.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 57 insertions(+), 1 deletions(-)
Side note about this function, which was written to ban all
ascii-incompatible charsets from entering commit objects. The idea of
mixing charsets in the same buffer without clear boundary does not
sound healthy. Plus, ident.c will silently drop '\n', '<' and '>' in
author/committer. If a hypothetical charset happens to place a letter
in those, um.. code points?, the letter will be dropped. But meh..
--
Duy
From: Jeff King <hidden> Date: 2016-06-15 22:53:07
On Tue, Feb 21, 2012 at 09:24:50PM +0700, Nguyen Thai Ngoc Duy wrote:
We rely on ASCII everywhere. We print "\n" directly without conversion
for example. The end result would be a mix of some encoding and ASCII
if they are incompatible. Do not do that.
In theory we could convert everything to utf-8 as intermediate medium,
process process process, then convert final output to the desired
encoding. But that's a lot of work (unless we have a pager-like
converter) with little real use. Users can just pipe everything to
iconv instead.
I'm not sure why we bother checking this. Using non-ASCII-superset
encodings is broken, yes, but are people actually doing that? I assume
that the common one is utf-16, and anybody using it will experience
severe breakage immediately. So are people actually doing this? Are
there actually encodings that will cause subtle breakage that we want to
catch?
-Peff
From: Jeff King <hidden> Date: 2016-06-15 22:53:07
On Tue, Feb 21, 2012 at 09:24:52PM +0700, Nguyen Thai Ngoc Duy wrote:
Commit object has its own format, which happens to be in ascii, but
not really subject to re-encoding.
There are only four areas that may be re-encoded: author line,
committer line, mergetag lines and commit body. Encoding of tags
embedded in mergetag lines is not decided by commit encoding, so leave
it out and consider it binary.
Is this worth the effort? Yes, re-encoding the ASCII bits of the commit
object is unnecessary. But do we actually handle encodings that are not
ASCII supersets? IOW, I could see the point if this is making it
possible to hold utf-16 names and messages in your commits (though why
you would want to do so is beyond me...). But my understanding is that
this is horribly broken anyway by other parts of the code. And even
looking at your code below:
Wouldn't this assert trigger in the presence of encodings which
contain ASCII NUL (e.g., wide encodings like utf-16)?
Is there an encoding you have in mind which would be helped by this?
-Peff
On Tue, Feb 21, 2012 at 09:24:52PM +0700, Nguyen Thai Ngoc Duy wrote:
quoted
Commit object has its own format, which happens to be in ascii, but
not really subject to re-encoding.
There are only four areas that may be re-encoded: author line,
committer line, mergetag lines and commit body. Encoding of tags
embedded in mergetag lines is not decided by commit encoding, so leave
it out and consider it binary.
Is this worth the effort? Yes, re-encoding the ASCII bits of the commit
object is unnecessary. But do we actually handle encodings that are not
ASCII supersets? IOW, I could see the point if this is making it
possible to hold utf-16 names and messages in your commits (though why
you would want to do so is beyond me...). But my understanding is that
this is horribly broken anyway by other parts of the code. And even
looking at your code below:
No, utf-16 and friends are out of question. 617/1168 supported
encodings in iconv translate chars 10,32-126 to something else, some
of them does not generate NUL. I suppose none of these are actually
used nowadays. Looking again, some don't even successfully translate
the given input. No, it's probably not worth the effort.
--
Duy
On Tue, Feb 21, 2012 at 09:24:50PM +0700, Nguyen Thai Ngoc Duy wrote:
quoted
We rely on ASCII everywhere. We print "\n" directly without conversion
for example. The end result would be a mix of some encoding and ASCII
if they are incompatible. Do not do that.
In theory we could convert everything to utf-8 as intermediate medium,
process process process, then convert final output to the desired
encoding. But that's a lot of work (unless we have a pager-like
converter) with little real use. Users can just pipe everything to
iconv instead.
I'm not sure why we bother checking this. Using non-ASCII-superset
encodings is broken, yes, but are people actually doing that? I assume
that the common one is utf-16, and anybody using it will experience
severe breakage immediately. So are people actually doing this? Are
there actually encodings that will cause subtle breakage that we want to
catch?
I did :-) once actually. But that's a good point, using unsuitable
encoding leads to garbage output, but no subtle breakage there. It'd
be nice to say "your encoding is not supported" than throw garbage,
but again probably no one did it but me, and I don't feel like doing
it again.
--
Duy
From: Peter Krefting <hidden> Date: 2016-06-15 22:53:08
Jeff King:
I'm not sure why we bother checking this. Using non-ASCII-superset
encodings is broken, yes, but are people actually doing that?
[...]
Are there actually encodings that will cause subtle breakage that we want
to catch?
Shift-JIS could be a problem; if implemented to the letter it would convert
0x5C to a Yen character and 0x7E as an overline. Otherwise I expect it only
being a problem with ISO 646 encodings, especially the ones that replace "@"
with something else [1].
Also any ISO 2022 seven-bit encoding (ISO-2022-{CN,JP,KR}) could cause
problems, especially if there is any preprocessing done on the string that
does not respect its state-shifting (most 0x21--0x7E characters can be lead
and trail bytes in their multi-byte modes).
--
\\// Peter - http://www.softwolves.pp.se/
[1] Trying to send Internet e-mail from a system using the extended
Swedish seven-bit encoding, where 0x40 mapped to "É", could
sometimes be a challenge.