* [PATCH] gettext: setlocale(LC_CTYPE, "") breaks Git's C function assumptions
@ 2010-08-12 22:08 Ævar Arnfjörð Bjarmason
2010-08-13 9:39 ` Jakub Narebski
0 siblings, 1 reply; 2+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2010-08-12 22:08 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Ævar Arnfjörð Bjarmason
Remove the setlocale/LC_CTYPE call from gettext.c, we only need
setlocale/LC_MESSAGES to use the message catalog, and setting LC_CTYPE
from the environment breaks Git's assumptions about C library
functions.
Under a non-C locale functions like vsnprintf become locale sensitive,
so that they'll e.g. refuse to process ISO-8895-1 data under a UTF-8
locale.
This triggered a "your vsnprintf is broken" error on Git's own
repository when inspecting v0.99.6~1 under a UTF-8 locale.
That commit contains a ISO-8859-1 encoded author name, which the
locale aware vsnprintf(3) won't interpolate in the format argument,
due to mismatch between the data encoding and the locale.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
This goes on top of the ab/i18n series in pu.
gettext.c | 1 -
t/t0203-gettext-setlocale-sanity.sh | 26 ++++++++++++++++++++++++++
2 files changed, 26 insertions(+), 1 deletions(-)
create mode 100755 t/t0203-gettext-setlocale-sanity.sh
diff --git a/gettext.c b/gettext.c
index 7ae5cae..db99742 100644
--- a/gettext.c
+++ b/gettext.c
@@ -17,6 +17,5 @@ extern void git_setup_gettext(void) {
}
(void)setlocale(LC_MESSAGES, "");
- (void)setlocale(LC_CTYPE, "");
(void)textdomain("git");
}
diff --git a/t/t0203-gettext-setlocale-sanity.sh b/t/t0203-gettext-setlocale-sanity.sh
new file mode 100755
index 0000000..a212460
--- /dev/null
+++ b/t/t0203-gettext-setlocale-sanity.sh
@@ -0,0 +1,26 @@
+#!/bin/sh
+#
+# Copyright (c) 2010 Ævar Arnfjörð Bjarmason
+#
+
+test_description="The Git C functions aren't broken by setlocale(3)"
+
+. ./lib-gettext.sh
+
+test_expect_success 'git show a ISO-8859-1 commit under C locale' '
+ . "$TEST_DIRECTORY"/t3901-8859-1.txt &&
+ test_commit "iso-c-commit" iso-under-c &&
+ git show >out 2>err &&
+ ! test -s err &&
+ grep -q "iso-c-commit" out
+'
+
+test_expect_success GETTEXT_LOCALE 'git show a ISO-8859-1 commit under a UTF-8 locale' '
+ . "$TEST_DIRECTORY"/t3901-8859-1.txt &&
+ test_commit "iso-utf8-commit" iso-under-utf8 &&
+ LANGUAGE=is LC_ALL="$is_IS_locale" git show >out 2>err &&
+ ! test -s err &&
+ grep -q "iso-utf8-commit" out
+'
+
+test_done
--
1.7.2.1.327.gfb40
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] gettext: setlocale(LC_CTYPE, "") breaks Git's C function assumptions
2010-08-12 22:08 [PATCH] gettext: setlocale(LC_CTYPE, "") breaks Git's C function assumptions Ævar Arnfjörð Bjarmason
@ 2010-08-13 9:39 ` Jakub Narebski
0 siblings, 0 replies; 2+ messages in thread
From: Jakub Narebski @ 2010-08-13 9:39 UTC (permalink / raw)
To: Ævar Arnfjörð Bjarmason; +Cc: git, Junio C Hamano
Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
> Remove the setlocale/LC_CTYPE call from gettext.c, we only need
> setlocale/LC_MESSAGES to use the message catalog, and setting LC_CTYPE
> from the environment breaks Git's assumptions about C library
> functions.
>
> Under a non-C locale functions like vsnprintf become locale sensitive,
> so that they'll e.g. refuse to process ISO-8895-1 data under a UTF-8
> locale.
>
> This triggered a "your vsnprintf is broken" error on Git's own
> repository when inspecting v0.99.6~1 under a UTF-8 locale.
>
> That commit contains a ISO-8859-1 encoded author name, which the
> locale aware vsnprintf(3) won't interpolate in the format argument,
> due to mismatch between the data encoding and the locale.
Sidenote: This commit was done probably before invention of 'encoding'
header, but it should be displayable anyway.
--
Jakub Narebski
Poland
ShadeHawk on #git
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-08-13 9:40 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-12 22:08 [PATCH] gettext: setlocale(LC_CTYPE, "") breaks Git's C function assumptions Ævar Arnfjörð Bjarmason
2010-08-13 9:39 ` Jakub Narebski
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.