GNU bug report logs - #18258
t0251-gpt-unicode.sh fails when the C.UTF-8 locale is unavailable

Previous Next

Package: parted;

Reported by: ludo <at> gnu.org (Ludovic Courtès)

Date: Wed, 13 Aug 2014 11:55:01 UTC

Severity: normal

Full log


Message #8 received at 18258 <at> debbugs.gnu.org (full text, mbox):

From: ludo <at> gnu.org (Ludovic Courtès)
To: "Brian C. Lane" <bcl <at> redhat.com>
Cc: 18258 <at> debbugs.gnu.org
Subject: Re: bug#18258: t0251-gpt-unicode.sh fails when the C.UTF-8 locale is
 unavailable
Date: Wed, 13 Aug 2014 21:55:26 +0200
"Brian C. Lane" <bcl <at> redhat.com> skribis:

> See my patch here:
>
> http://lists.alioth.debian.org/pipermail/parted-devel/2014-July/004568.html

-export LC_ALL=C.UTF-8
+if [ -e "/usr/share/locale/en_US/" ]; then
+    export LC_ALL=en_US.UTF-8
+else
+    export LC_ALL=C.UTF-8
+fi

The problem is that this directory is not necessarily where locale data
resides.

One way to check whether the locale encoding is supported would be
with ‘wc -m’:

--8<---------------cut here---------------start------------->8---
$ printf 'foo\341\264\244'|LC_ALL=C wc -m
6

$ printf 'foo\341\264\244'|LC_ALL=en_US.utf8 wc -m
4
--8<---------------cut here---------------end--------------->8---

The test could look for a valid UTF-8 locale like this:

--8<---------------cut here---------------start------------->8---
found_locale=no
for locale in en_US de_DE fr_FR es_ES
do
  LC_ALL="$locale.utf8"

  # In a UTF-8 locale, the string below prints as 4 characters.
  if [ `printf 'foo\341\264\244' | wc -m` -eq 4 ]; then
    found_locale=yes
    break
  fi
done

if [ "$found_locale" != "yes" ]; then
  echo "no valid UTF-8 locale found; skipping" >&2
  exit 77
fi
--8<---------------cut here---------------end--------------->8---

Thoughts?

Thanks,
Ludo’.




This bug report was last modified 10 years and 302 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.