Skip to content

Commit 81050ac

Browse files
nafmogitster
authored andcommitted
commit: reject non-characters
Unicode clause D14 defines all characters U+nFFFE and U+nFFFF (where 0 <= n <= 10h) as well as the range U+FDD0..U+FDEF as non-characters, reserved for internal use only. Disallow these characters in commit messages as they are normally not recommended for interchange. Signed-off-by: Peter Krefting <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e82bd6c commit 81050ac

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

commit.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,8 +1305,11 @@ static int find_invalid_utf8(const char *buf, int len)
13051305
/* Surrogates are only for UTF-16 and cannot be encoded in UTF-8. */
13061306
if ((codepoint & 0x1ff800) == 0xd800)
13071307
return bad_offset;
1308-
/* U+FFFE and U+FFFF are guaranteed non-characters. */
1309-
if ((codepoint & 0x1ffffe) == 0xfffe)
1308+
/* U+xxFFFE and U+xxFFFF are guaranteed non-characters. */
1309+
if ((codepoint & 0xffffe) == 0xfffe)
1310+
return bad_offset;
1311+
/* So are anything in the range U+FDD0..U+FDEF. */
1312+
if (codepoint >= 0xfdd0 && codepoint <= 0xfdef)
13101313
return bad_offset;
13111314
}
13121315
return -1;

t/t3900-i18n-commit.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,24 @@ test_expect_success 'UTF-8 overlong sequences rejected' '
5858
grep "did not conform" "$HOME"/stderr
5959
'
6060

61+
test_expect_success 'UTF-8 non-characters refused' '
62+
test_when_finished "rm -f $HOME/stderr $HOME/invalid" &&
63+
echo "UTF-8 non-character 1" >F &&
64+
printf "Commit message\n\nNon-character:\364\217\277\276\n" \
65+
>"$HOME/invalid" &&
66+
git commit -a -F "$HOME/invalid" 2>"$HOME"/stderr &&
67+
grep "did not conform" "$HOME"/stderr
68+
'
69+
70+
test_expect_success 'UTF-8 non-characters refused' '
71+
test_when_finished "rm -f $HOME/stderr $HOME/invalid" &&
72+
echo "UTF-8 non-character 2." >F &&
73+
printf "Commit message\n\nNon-character:\357\267\220\n" \
74+
>"$HOME/invalid" &&
75+
git commit -a -F "$HOME/invalid" 2>"$HOME"/stderr &&
76+
grep "did not conform" "$HOME"/stderr
77+
'
78+
6179
for H in ISO8859-1 eucJP ISO-2022-JP
6280
do
6381
test_expect_success "$H setup" '

0 commit comments

Comments
 (0)