wcwidth: Ensure width 1, not 2, for ambiguous characters.
authorBruno Haible <bruno@clisp.org>
Sun, 5 May 2019 11:18:23 +0000 (13:18 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 5 May 2019 11:19:12 +0000 (13:19 +0200)
Reported by Kiyoshi KANAZAWA <yoi_no_myoujou@yahoo.co.jp>
via Akim Demaille <akim.demaille@gmail.com>.

* m4/wcwidth.m4 (gl_FUNC_WCWIDTH): Check the width of U+2202. Use an
en_US.UTF-8 locale, since that is more likely to be present than an
fr_FR.UTF-8 locale.
* tests/test-wcwidth.c (main): Check the width of U+2202.
* doc/posix-functions/wcwidth.texi: Mention the issue.

ChangeLog
doc/posix-functions/wcwidth.texi
m4/wcwidth.m4
tests/test-wcwidth.c

index 92aa64a4f937c7d5359e6cf9e890ebae569dc2f1..31e05adbdb47ed689aaa8aad2882a9a4d5c4a2fe 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2019-05-05  Bruno Haible  <bruno@clisp.org>
+
+       wcwidth: Ensure width 1, not 2, for ambiguous characters.
+       Reported by Kiyoshi KANAZAWA <yoi_no_myoujou@yahoo.co.jp>
+       via Akim Demaille <akim.demaille@gmail.com>.
+       * m4/wcwidth.m4 (gl_FUNC_WCWIDTH): Check the width of U+2202. Use an
+       en_US.UTF-8 locale, since that is more likely to be present than an
+       fr_FR.UTF-8 locale.
+       * tests/test-wcwidth.c (main): Check the width of U+2202.
+       * doc/posix-functions/wcwidth.texi: Mention the issue.
+
 2019-05-03  Paul Eggert  <eggert@cs.ucla.edu>
 
        Port manywarnings to GCC 9
index 741be8ea32b81537e09a91169ab45279c097a2e8..ecdf758a31161b08c972a9033ee658f68128cef7 100644 (file)
@@ -18,6 +18,10 @@ glibc 2.8.
 This function handles combining characters in UTF-8 locales incorrectly on some
 platforms:
 Mac OS X 10.3, OpenBSD 5.8.
+@item
+This function returns 2 for characters with ambiguous east asian width, even in
+Western locales, on some platforms:
+Solaris 11.4.
 @end itemize
 
 Portability problems not fixed by Gnulib:
index 3952fd27b929cbae7843a54064621005883c4965..e9b5bf48fc27be55608275501559dc2766c7b6d3 100644 (file)
@@ -1,4 +1,4 @@
-# wcwidth.m4 serial 28
+# wcwidth.m4 serial 29
 dnl Copyright (C) 2006-2019 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -54,6 +54,8 @@ AC_DEFUN([gl_FUNC_WCWIDTH],
     dnl On OSF/1 5.1, wcwidth(0x200B) (ZERO WIDTH SPACE) returns 1.
     dnl On OpenBSD 5.8, wcwidth(0xFF1A) (FULLWIDTH COLON) returns 0.
     dnl This leads to bugs in 'ls' (coreutils).
+    dnl On Solaris 11.4, wcwidth(0x2202) (PARTIAL DIFFERENTIAL) returns 2,
+    dnl even in Western locales.
     AC_CACHE_CHECK([whether wcwidth works reasonably in UTF-8 locales],
       [gl_cv_func_wcwidth_works],
       [
@@ -80,7 +82,7 @@ int wcwidth (int);
 int main ()
 {
   int result = 0;
-  if (setlocale (LC_ALL, "fr_FR.UTF-8") != NULL)
+  if (setlocale (LC_ALL, "en_US.UTF-8") != NULL)
     {
       if (wcwidth (0x0301) > 0)
         result |= 1;
@@ -90,6 +92,8 @@ int main ()
         result |= 4;
       if (wcwidth (0xFF1A) == 0)
         result |= 8;
+      if (wcwidth (0x2202) > 1)
+        result |= 16;
     }
   return result;
 }]])],
index eb7bdd2e66258205631637019c261696517e1947..8e9cea3e4970f4a4949c8b7e612cf3be7b97390c 100644 (file)
@@ -72,6 +72,22 @@ main ()
       ASSERT (wcwidth (0x200B) == 0);
       ASSERT (wcwidth (0xFEFF) <= 0);
 
+      /* Test width of some math symbols.
+         U+2202 is marked as having ambiguous width (A) in EastAsianWidth.txt
+         (see <https://www.unicode.org/Public/12.0.0/ucd/EastAsianWidth.txt>).
+         The Unicode Standard Annex 11
+         <https://www.unicode.org/reports/tr11/tr11-36.html>
+         says
+           "Ambiguous characters behave like wide or narrow characters
+            depending on the context (language tag, script identification,
+            associated font, source of data, or explicit markup; all can
+            provide the context). If the context cannot be established
+            reliably, they should be treated as narrow characters by default."
+         For wcwidth(), the only available context information is the locale.
+         "fr_FR.UTF-8" is a Western locale, not an East Asian locale, therefore
+         U+2202 should be treated like a narrow character.  */
+      ASSERT (wcwidth (0x2202) == 1);
+
       /* Test width of some CJK characters.  */
       ASSERT (wcwidth (0x3000) == 2);
       ASSERT (wcwidth (0xB250) == 2);