From 6b9110352459e246e99a5c2d396f5dc42d0cd32b Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Sat, 21 Jun 2008 17:50:05 +0200
Subject: [PATCH] Avoid question marks in proper_name_utf8 result.

---
 ChangeLog        |  6 ++++++
 lib/propername.c | 33 +++++++++++++++++++++++++++++++--
 2 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index bdb444afc6..81c0893f82 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2008-06-21  Bruno Haible  <bruno@clisp.org>
+
+	* lib/propername.c (proper_name_utf8): Don't use the transliterated
+	result if it contains question marks.
+	Reported by Michael Geng <linux@michaelgeng.de>.
+
 2008-06-19  Bruno Haible  <bruno@clisp.org>
 
 	Fix CVS-ism.
diff --git a/lib/propername.c b/lib/propername.c
index 0d3681e264..5cd4d8f49a 100644
--- a/lib/propername.c
+++ b/lib/propername.c
@@ -205,15 +205,32 @@ proper_name_utf8 (const char *name_ascii, const char *name_utf8)
 # if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2) || __GLIBC__ > 2 \
      || _LIBICONV_VERSION >= 0x0105
       {
+	char *converted_translit;
+
 	size_t len = strlen (locale_code);
 	char *locale_code_translit = XNMALLOC (len + 10 + 1, char);
 	memcpy (locale_code_translit, locale_code, len);
 	memcpy (locale_code_translit + len, "//TRANSLIT", 10 + 1);
 
-	name_converted_translit = alloc_name_converted_translit =
+	converted_translit =
 	  xstr_iconv (name_utf8, "UTF-8", locale_code_translit);
 
 	free (locale_code_translit);
+
+	if (converted_translit != NULL)
+	  {
+#  if !_LIBICONV_VERSION
+	    /* Don't use the transliteration if it added question marks.
+	       glibc's transliteration falls back to question marks; libiconv's
+	       transliteration does not.
+	       mbschr is equivalent to strchr in this case.  */
+	    if (strchr (converted_translit, '?') != NULL)
+	      free (converted_translit);
+	    else
+#  endif
+	      name_converted_translit = alloc_name_converted_translit =
+		converted_translit;
+	  }
       }
 # endif
 #endif
@@ -270,7 +287,7 @@ proper_name_utf8 (const char *name_ascii, const char *name_utf8)
     }
 }
 
-#ifdef TEST
+#ifdef TEST1
 # include <locale.h>
 int
 main (int argc, char *argv[])
@@ -281,3 +298,15 @@ main (int argc, char *argv[])
   return 0;
 }
 #endif
+
+#ifdef TEST2
+# include <locale.h>
+# include <stdio.h>
+int
+main (int argc, char *argv[])
+{
+  setlocale (LC_ALL, "");
+  printf ("%s\n", proper_name_utf8 ("Franc,ois Pinard", "Fran\303\247ois Pinard"));
+  return 0;
+}
+#endif
-- 
2.39.5