]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-133740: Fix locale.nl_langinfo(ALT_DIGITS) (#134468)
authorVictor Stinner <vstinner@python.org>
Thu, 22 May 2025 14:05:07 +0000 (16:05 +0200)
committerGitHub <noreply@github.com>
Thu, 22 May 2025 14:05:07 +0000 (16:05 +0200)
Set the LC_CTYPE locale to the LC_TIME locale even if
nl_langinfo(ALT_DIGITS) result is ASCII. The result is a list
separated by NUL characters and the code only checks the first list
item which can be ASCII whereas following items are non-ASCII.

Fix test__locale for the uk_UA locale on RHEL 7.

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Modules/_localemodule.c

index ad618398d5b824f3b4a7633b89ebaf0a73558ed3..c1f56008b7c49e3c9680f51cc77835ed49fc527c 100644 (file)
@@ -692,7 +692,17 @@ _locale_nl_langinfo_impl(PyObject *module, int item)
             result = result != NULL ? result : "";
             char *oldloc = NULL;
             if (langinfo_constants[i].category != LC_CTYPE
-                && !is_all_ascii(result)
+                && (
+#ifdef __GLIBC__
+                    // gh-133740: Always change the locale for ALT_DIGITS and ERA
+#  ifdef ALT_DIGITS
+                    item == ALT_DIGITS ||
+#  endif
+#  ifdef ERA
+                    item == ERA ||
+#  endif
+#endif
+                    !is_all_ascii(result))
                 && change_locale(langinfo_constants[i].category, &oldloc) < 0)
             {
                 return NULL;