public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Michał Górny" <mgorny@gentoo.org>
To: gentoo-dev@lists.gentoo.org
Cc: python@gentoo.org, "Michał Górny" <mgorny@gentoo.org>
Subject: [gentoo-dev] [PATCH] python-utils-r1.eclass: python_export_utf8_locale(), ensure sane locale
Date: Sun, 15 Nov 2015 10:21:51 +0100	[thread overview]
Message-ID: <1447579311-32588-1-git-send-email-mgorny@gentoo.org> (raw)

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.
---
 eclass/python-utils-r1.eclass | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/eclass/python-utils-r1.eclass b/eclass/python-utils-r1.eclass
index 6ff1dd1..5e3338f 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
 
-- 
2.6.3



             reply	other threads:[~2015-11-15  9:22 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-15  9:21 Michał Górny [this message]
2015-11-28 19:10 ` [gentoo-dev] [PATCH] python-utils-r1.eclass: python_export_utf8_locale(), ensure sane locale Michał Górny
2015-12-18  1:23   ` Tyler Pohl
2015-12-18  2:07     ` Michael Orlitzky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1447579311-32588-1-git-send-email-mgorny@gentoo.org \
    --to=mgorny@gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    --cc=python@gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox