commit:     cf566f5832b94fb10e9588aa116143ed5d525c43
Author:     Ulrich Müller <ulm <AT> gentoo <DOT> org>
AuthorDate: Wed Oct 22 15:55:40 2025 +0000
Commit:     Ulrich Müller <ulm <AT> gentoo <DOT> org>
CommitDate: Wed Oct 22 15:55:40 2025 +0000
URL:        https://gitweb.gentoo.org/proj/eselect.git/commit/?id=cf566f58

Sanitise the list of locales in locale module

* modules/locale.eselect (find_targets): List only C, POSIX and
UTF-8 locales, and make the output unique. Bug 964713, bug 962878.
(do_list, do_set): Use mapfile for the targets array.

Bug: https://bugs.gentoo.org/964713
Bug: https://bugs.gentoo.org/962878
Signed-off-by: Ulrich Müller <ulm <AT> gentoo.org>

 ChangeLog              |  6 ++++++
 modules/locale.eselect | 25 +++++++++++++++++--------
 2 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 132e44e..7b47ff6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2025-10-22  Ulrich Müller  <[email protected]>
+
+       * modules/locale.eselect (find_targets): List only C, POSIX and
+       UTF-8 locales, and make the output unique. Bug 964713, bug 962878.
+       (do_list, do_set): Use mapfile for the targets array.
+
 2025-03-22  Ulrich Müller  <[email protected]>
 
        * configure.ac: Update version to 1.4.30.

diff --git a/modules/locale.eselect b/modules/locale.eselect
index 92c5fc4..fa9a69a 100644
--- a/modules/locale.eselect
+++ b/modules/locale.eselect
@@ -22,14 +22,24 @@ validate_locale() {
 
 # find a list of valid targets
 find_targets() {
-       local list cur
-
-       list=$(locale_list)
-       echo ${list}
+       local lang cur
+       local -A seen
+
+       while IFS= read -r lang; do
+               case ${lang} in
+                       C|POSIX) ;;
+                       *.[Uu][Tt][Ff]?(-)8?(@*))
+                               lang=${lang/.[Uu][Tt][Ff]?(-)8/.UTF-8} ;;
+                       *) continue ;;
+               esac
+               [[ -n ${seen[${lang}]} ]] && continue
+               seen[${lang}]=1
+               printf "%s\n" "${lang}"
+       done < <(locale_list)
 
        # also output the current value if it isn't in our list
        cur=$(read_env_value)
-       [[ -n ${cur} ]] && ! has "${cur}" ${list} && echo "${cur}"
+       [[ -n ${cur} && -z ${seen[${cur}]} ]] && printf "%s\n" "${cur}"
 }
 
 # read variable value from config file
@@ -69,11 +79,10 @@ do_list() {
 
        local cur targets i
        cur=$(read_env_value)
-       targets=( $(find_targets) )
+       mapfile -t targets < <(find_targets)
 
        write_list_start "Available targets for the LANG variable:"
        for (( i = 0; i < ${#targets[@]}; i = i + 1 )); do
-               targets[i]="${targets[i]}"
                # display a star to indicate the currently chosen version
                [[ ${targets[i]} = "${cur}" ]] \
                        && targets[i]=$(highlight_marker "${targets[i]}")
@@ -111,7 +120,7 @@ do_set() {
 
        # target may be specified by its name or its index
        if is_number "${target}"; then
-               targets=( $(find_targets) )
+               mapfile -t targets < <(find_targets)
                [[ ${target} -ge 1 && ${target} -le ${#targets[@]} ]] \
                        || die -q "Number out of range: $1"
                target=${targets[target-1]%%:*}

Reply via email to