1
0
mirror of https://git.savannah.gnu.org/git/gnulib.git synced 2026-10-24 00:48:56 +03:00

bcp47: Fix handling of variants of length 4.

Reported by Patrice Dumas <pertusus@gnu.org> in
<https://lists.gnu.org/archive/html/bug-gnulib/2026-04/msg00154.html>.

* lib/bcp47.c (bcp47_to_xpg): Don't parse a variant of length 4 that
contains some digits as a script.
* tests/test-bcp47.c (main): Add a test case with a variant of length 4.
This commit is contained in:
Bruno Haible
2026-04-24 15:57:52 +02:00
parent 5926e89900
commit 6f68489dda
3 changed files with 20 additions and 1 deletions

View File

@@ -1,3 +1,12 @@
2026-04-24 Bruno Haible <bruno@clisp.org>
bcp47: Fix handling of variants of length 4.
Reported by Patrice Dumas <pertusus@gnu.org> in
<https://lists.gnu.org/archive/html/bug-gnulib/2026-04/msg00154.html>.
* lib/bcp47.c (bcp47_to_xpg): Don't parse a variant of length 4 that
contains some digits as a script.
* tests/test-bcp47.c (main): Add a test case with a variant of length 4.
2026-04-23 Paul Eggert <eggert@cs.ucla.edu>
wchar-h: <string.h> namespace cleanup

View File

@@ -405,7 +405,14 @@ bcp47_to_xpg (char *xpg, const char *bcp47, const char *codeset)
p++;
size_t subtag_len = p - subtag_start;
if (!past_script && subtag_len == 4)
if (!past_script
&& subtag_len == 4
/* Subtags of length 4 that contain digits are variants,
not scripts. */
&& !(subtag_start[0] >= '0' && subtag_start[0] <= '9')
&& !(subtag_start[1] >= '0' && subtag_start[1] <= '9')
&& !(subtag_start[2] >= '0' && subtag_start[2] <= '9')
&& !(subtag_start[3] >= '0' && subtag_start[3] <= '9'))
{
/* Parsed -script. */
script_start = subtag_start;

View File

@@ -146,6 +146,9 @@ main ()
test_correspondence ("ca", "ca");
test_correspondence ("ca@valencia", "ca-valencia");
/* Languages with a spelling rules variant. */
test_correspondence ("de@1901", "de-1901");
/* Test xpg_to_bcp47 with an encoding. */
{
char buf[BCP47_MAX];