diff options
author | Ludovic Courtès <ludo@gnu.org> | 2012-02-18 00:04:17 +0100 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2012-02-18 00:04:17 +0100 |
commit | 5de0053178b4acc793ae62838175e5f3ab56c603 (patch) | |
tree | 6d6d121a942bc161e87b3480380cf148a6be71ea | |
parent | cac24946da089e1e1fddf9c9dc7ae7dae9e29014 (diff) |
Don't fail when locale env. vars specify a dot-less locale name.
Fixes <http://bugs.gnu.org/10742>.
Reported by Alírio Eyng <alirioeyng@ig.com.br>.
* gnulib-local/lib/localcharset.c.diff (environ_locale_charset): Change
to set CODESET to "" when LOCALE lacks a dot. Return "ISO-8859-1"
when CODESET is the empty string.
* lib/localcharset.c: Update.
* test-suite/standalone/Makefile.am (check_SCRIPTS): Add
`test-command-line-encoding2'.
(TESTS): Likewise.
* test-suite/standalone/test-command-line-encoding2: New file.
-rw-r--r-- | gnulib-local/lib/localcharset.c.diff | 51 | ||||
-rw-r--r-- | lib/localcharset.c | 8 | ||||
-rw-r--r-- | test-suite/standalone/Makefile.am | 5 | ||||
-rwxr-xr-x | test-suite/standalone/test-command-line-encoding2 | 20 |
4 files changed, 52 insertions, 32 deletions
diff --git a/gnulib-local/lib/localcharset.c.diff b/gnulib-local/lib/localcharset.c.diff index 2b27ee479..6f216ad80 100644 --- a/gnulib-local/lib/localcharset.c.diff +++ b/gnulib-local/lib/localcharset.c.diff @@ -5,28 +5,10 @@ rationale. --- a/lib/localcharset.c 2011-12-14 23:10:58.000000000 +0100 +++ b/lib/localcharset.c 2011-12-15 00:45:12.000000000 +0100 -@@ -527,6 +527,76 @@ locale_charset (void) - codeset = ""; +@@ -545,3 +545,74 @@ locale_charset (void) - /* Resolve alias. */ -+ for (aliases = get_charset_aliases (); -+ *aliases != '\0'; -+ aliases += strlen (aliases) + 1, aliases += strlen (aliases) + 1) -+ if (strcmp (codeset, aliases) == 0 -+ || (aliases[0] == '*' && aliases[1] == '\0')) -+ { -+ codeset = aliases + strlen (aliases) + 1; -+ break; -+ } -+ -+ /* Don't return an empty string. GNU libc and GNU libiconv interpret -+ the empty string as denoting "the locale's character encoding", -+ thus GNU libiconv would call this function a second time. */ -+ if (codeset[0] == '\0') -+ codeset = "ASCII"; -+ -+ return codeset; -+} + return codeset; + } + +/* A variant of the above, without calls to `setlocale', `nl_langinfo', + etc. */ @@ -71,14 +53,29 @@ rationale. + strcpy (buf, "ASCII"); + return buf; + } -+ -+ /* Resolve through the charset.alias file. */ -+ codeset = locale; ++ else ++ codeset = ""; + } + else + codeset = ""; + + /* Resolve alias. */ - for (aliases = get_charset_aliases (); - *aliases != '\0'; - aliases += strlen (aliases) + 1, aliases += strlen (aliases) + 1) ++ for (aliases = get_charset_aliases (); ++ *aliases != '\0'; ++ aliases += strlen (aliases) + 1, aliases += strlen (aliases) + 1) ++ if (strcmp (codeset, aliases) == 0 ++ || (aliases[0] == '*' && aliases[1] == '\0')) ++ { ++ codeset = aliases + strlen (aliases) + 1; ++ break; ++ } ++ ++ /* Don't return an empty string. GNU libc and GNU libiconv interpret ++ the empty string as denoting "the locale's character encoding", ++ thus GNU libiconv would call this function a second time. */ ++ if (codeset[0] == '\0') ++ /* Default to Latin-1, for backward compatibility with Guile 1.8. */ ++ codeset = "ISO-8859-1"; ++ ++ return codeset; ++} diff --git a/lib/localcharset.c b/lib/localcharset.c index 47a6e5d5b..2c06328cb 100644 --- a/lib/localcharset.c +++ b/lib/localcharset.c @@ -589,9 +589,8 @@ environ_locale_charset (void) strcpy (buf, "ASCII"); return buf; } - - /* Resolve through the charset.alias file. */ - codeset = locale; + else + codeset = ""; } else codeset = ""; @@ -611,7 +610,8 @@ environ_locale_charset (void) the empty string as denoting "the locale's character encoding", thus GNU libiconv would call this function a second time. */ if (codeset[0] == '\0') - codeset = "ASCII"; + /* Default to Latin-1, for backward compatibility with Guile 1.8. */ + codeset = "ISO-8859-1"; return codeset; } diff --git a/test-suite/standalone/Makefile.am b/test-suite/standalone/Makefile.am index d8cfafa25..daa3d0744 100644 --- a/test-suite/standalone/Makefile.am +++ b/test-suite/standalone/Makefile.am @@ -1,7 +1,7 @@ ## Process this file with automake to produce Makefile.in. ## ## Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, -## 2011 Free Software Foundation, Inc. +## 2011, 2012 Free Software Foundation, Inc. ## ## This file is part of GUILE. ## @@ -85,6 +85,9 @@ EXTRA_DIST += test-import-order-a.scm test-import-order-b.scm \ check_SCRIPTS += test-command-line-encoding TESTS += test-command-line-encoding +check_SCRIPTS += test-command-line-encoding2 +TESTS += test-command-line-encoding2 + # test-num2integral test_num2integral_SOURCES = test-num2integral.c test_num2integral_CFLAGS = ${test_cflags} diff --git a/test-suite/standalone/test-command-line-encoding2 b/test-suite/standalone/test-command-line-encoding2 new file mode 100755 index 000000000..536945bc2 --- /dev/null +++ b/test-suite/standalone/test-command-line-encoding2 @@ -0,0 +1,20 @@ +#!/bin/sh + +# Choose a locale name that lacks a dot followed by the encoding name. +# This should not confuse `environ_locale_charset'. +# See <http://bugs.gnu.org/10742> for the original bug report. +LC_ALL="en_US" +export LC_ALL +unset LANG +unset LC_CTYPE + +exec guile -q -s "$0" "hello" +!# + +;; Make sure our argument was suitable decoded. +(exit (string=? (cadr (program-arguments)) "hello")) + +;; Local Variables: +;; mode: scheme +;; coding: iso-8859-1 +;; End: |