summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichał Górny <mgorny@gentoo.org>2015-11-15 10:20:22 +0100
committerMichał Górny <mgorny@gentoo.org>2015-11-28 20:09:06 +0100
commit09475a2f59254b3a0247bab6937084e28b634d37 (patch)
treea07027a570bae6b0d8bb84bd1f8496d67b3c3c38 /eclass/python-utils-r1.eclass
parentfortran-2.eclass: Fix for missing case end (diff)
downloadgentoo-09475a2f59254b3a0247bab6937084e28b634d37.tar.gz
gentoo-09475a2f59254b3a0247bab6937084e28b634d37.tar.bz2
gentoo-09475a2f59254b3a0247bab6937084e28b634d37.zip
python-utils-r1.eclass: python_export_utf8_locale(), ensure sane locale
Ensure that the locale selected by python_export_utf8_locale() conforms to POSIX-ish case conversions. Otherwise, we may accidentally force a locale that will break random ebuilds and programs.
Diffstat (limited to 'eclass/python-utils-r1.eclass')
-rw-r--r--eclass/python-utils-r1.eclass24
1 files changed, 22 insertions, 2 deletions
diff --git a/eclass/python-utils-r1.eclass b/eclass/python-utils-r1.eclass
index 6ff1dd17bab2..5e3338f35b53 100644
--- a/eclass/python-utils-r1.eclass
+++ b/eclass/python-utils-r1.eclass
@@ -1141,6 +1141,24 @@ python_fix_shebang() {
done
}
+# @FUNCTION: _python_check_locale_sanity
+# @USAGE: <locale>
+# @RETURN: 0 if sane, 1 otherwise
+# @DESCRIPTION:
+# Check whether the specified locale sanely maps between lowercase
+# and uppercase ASCII characters.
+_python_check_locale_sanity() {
+ local -x LC_CTYPE=${1}
+ local IFS=
+
+ local lc=( {a..z} )
+ local uc=( {A..Z} )
+ local input=${lc[*]}${uc[*]}
+
+ local output=$(tr '[:lower:][:upper:]' '[:upper:][:lower:]' <<<"${input}")
+ [[ ${output} == "${uc[*]}${lc[*]}" ]]
+}
+
# @FUNCTION: python_export_utf8_locale
# @RETURN: 0 on success, 1 on failure.
# @DESCRIPTION:
@@ -1165,8 +1183,10 @@ python_export_utf8_locale() {
for lang in ${locales}; do
if [[ $(LC_CTYPE=${lang} locale charmap 2>/dev/null) == UTF-8 ]]; then
- export LC_CTYPE=${lang}
- return 0
+ if _python_check_locale_sanity "${lang}"; then
+ export LC_CTYPE=${lang}
+ return 0
+ fi
fi
done