#939445 libc6: Localized sorting has unexpected change in zh_CN locale

Package:
libc6
Source:
glibc
Description:
GNU C Library: Shared libraries
Submitter:
WHR
Date:
2019-11-16 03:36:03 UTC
Severity:
normal
#939445#5
Date:
2019-09-05 02:49:34 UTC
From:
To:
Hi, I found the item sorting has surprising change in Debian Buster when using
zh_CN locale; the Chinese characters are now sorted before English letters. I
usually using LANG=zh_CN.UTF-8 to display localized messages in my system;
however this change affected convenience for me of finding items.
The default sorting mode of ls(1) has been affected by this, I don't exactly
known how ls(1) sorting the files, but I guess the source of the issue is from
the GLIBC, because bash(1) is also affected when trying something like
'echo *'.

For example:

root@debian:~/test# export | grep -F -e LANG -e LC_
declare -x LANG="C.UTF-8"
root@debian:~/test# ls -l
total 40
drwxr-xr-x 2 root root 4096 Sep  4 22:24 111
drwxr-xr-x 2 root root 4096 Sep  4 22:24 222
drwxr-xr-x 2 root root 4096 Sep  4 22:24 aaa
drwxr-xr-x 2 root root 4096 Sep  4 22:24 bbb
drwxr-xr-x 2 root root 4096 Sep  4 22:24 ccc
drwxr-xr-x 2 root root 4096 Sep  4 22:24 test
drwxr-xr-x 2 root root 4096 Sep  4 22:24 z.测试
drwxr-xr-x 2 root root 4096 Sep  4 22:24 zzz
drwxr-xr-x 2 root root 4096 Sep  4 22:24 一
drwxr-xr-x 2 root root 4096 Sep  4 22:24 测试
root@debian:~/test# LANG=en_US.UTF-8 ls -l
total 40
drwxr-xr-x 2 root root 4096 Sep  4 22:24 111
drwxr-xr-x 2 root root 4096 Sep  4 22:24 222
drwxr-xr-x 2 root root 4096 Sep  4 22:24 aaa
drwxr-xr-x 2 root root 4096 Sep  4 22:24 bbb
drwxr-xr-x 2 root root 4096 Sep  4 22:24 ccc
drwxr-xr-x 2 root root 4096 Sep  4 22:24 test
drwxr-xr-x 2 root root 4096 Sep  4 22:24 zzz
drwxr-xr-x 2 root root 4096 Sep  4 22:24 z.测试
drwxr-xr-x 2 root root 4096 Sep  4 22:24 一
drwxr-xr-x 2 root root 4096 Sep  4 22:24 测试
root@debian:~/test# LANG=zh_CN.UTF-8 ls -l
总用量 40
drwxr-xr-x 2 root root 4096 9月   4 22:24 111
drwxr-xr-x 2 root root 4096 9月   4 22:24 222
drwxr-xr-x 2 root root 4096 9月   4 22:24 测试
drwxr-xr-x 2 root root 4096 9月   4 22:24 一
drwxr-xr-x 2 root root 4096 9月   4 22:24 aaa
drwxr-xr-x 2 root root 4096 9月   4 22:24 bbb
drwxr-xr-x 2 root root 4096 9月   4 22:24 ccc
drwxr-xr-x 2 root root 4096 9月   4 22:24 test
drwxr-xr-x 2 root root 4096 9月   4 22:24 z.测试
drwxr-xr-x 2 root root 4096 9月   4 22:24 zzz
root@debian:~/test# LANG=zh_TW.UTF-8 ls -l
總計 40
drwxr-xr-x 2 root root 4096  9月  4 22:24 111
drwxr-xr-x 2 root root 4096  9月  4 22:24 222
drwxr-xr-x 2 root root 4096  9月  4 22:24 aaa
drwxr-xr-x 2 root root 4096  9月  4 22:24 bbb
drwxr-xr-x 2 root root 4096  9月  4 22:24 ccc
drwxr-xr-x 2 root root 4096  9月  4 22:24 test
drwxr-xr-x 2 root root 4096  9月  4 22:24 zzz
drwxr-xr-x 2 root root 4096  9月  4 22:24 z.测试
drwxr-xr-x 2 root root 4096  9月  4 22:24 一
drwxr-xr-x 2 root root 4096  9月  4 22:24 测试
root@debian:~/test# bash -c 'echo *'
111 222 aaa bbb ccc test z.测试 zzz 一 测试
root@debian:~/test# LANG=en_US.UTF-8 bash -c 'echo *'
111 222 aaa bbb ccc test zzz z.测试 一 测试
root@debian:~/test# LANG=zh_CN.UTF-8 bash -c 'echo *'
111 222 测试 一 aaa bbb ccc test z.测试 zzz
root@debian:~/test# LANG=zh_TW.UTF-8 bash -c 'echo *'
111 222 aaa bbb ccc test zzz z.测试 一 测试

It seems only zh_CN has this problem, zh_TW was not.
I has tried to workaround this by setting 'LC_*' variables, but none has worked.
I'm really disliked this change, but I still don't want to give up on the zh_CN
locale that provided by C library.

#939445#10
Date:
2019-11-16 03:33:18 UTC
From:
To:
I found a workaround for this issue.

I has put followings into '/etc/profile':

if [ "${LANG%%.*}" = zh_CN ]; then
    # Workaround for bug 939445
    export LANG="zh_TW${LANG#zh_CN}"
    [ -z "$LANGUAGE" ] && export LANGUAGE=zh_CN:zh_TW:en_US:en_GB
fi

This changes LANG from zh_CN to zh_TW so that sorting item would done
in zh_TW style, and UI messages will still perfer zh_CN because of the
LANGUAGE variable.