From 620857c4dccb8f0548cdb855f6b2f46ebea3919e Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 5 May 2019 13:18:23 +0200 Subject: [PATCH] wcwidth: Ensure width 1, not 2, for ambiguous characters. Reported by Kiyoshi KANAZAWA via Akim Demaille . * 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 | 11 +++++++++++ doc/posix-functions/wcwidth.texi | 4 ++++ m4/wcwidth.m4 | 8 ++++++-- tests/test-wcwidth.c | 16 ++++++++++++++++ 4 files changed, 37 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 92aa64a4f9..31e05adbdb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2019-05-05 Bruno Haible + + wcwidth: Ensure width 1, not 2, for ambiguous characters. + Reported by Kiyoshi KANAZAWA + via Akim Demaille . + * 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 Port manywarnings to GCC 9 diff --git a/doc/posix-functions/wcwidth.texi b/doc/posix-functions/wcwidth.texi index 741be8ea32..ecdf758a31 100644 --- a/doc/posix-functions/wcwidth.texi +++ b/doc/posix-functions/wcwidth.texi @@ -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: diff --git a/m4/wcwidth.m4 b/m4/wcwidth.m4 index 3952fd27b9..e9b5bf48fc 100644 --- a/m4/wcwidth.m4 +++ b/m4/wcwidth.m4 @@ -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; }]])], diff --git a/tests/test-wcwidth.c b/tests/test-wcwidth.c index eb7bdd2e66..8e9cea3e49 100644 --- a/tests/test-wcwidth.c +++ b/tests/test-wcwidth.c @@ -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 ). + The Unicode Standard Annex 11 + + 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); -- 2.39.5