b2938d
From 4cfbe5474a5c5f852a6dbf0138dc796c2800be93 Mon Sep 17 00:00:00 2001
b2938d
From: Karl Williamson <khw@cpan.org>
b2938d
Date: Wed, 30 Dec 2020 05:55:08 -0700
b2938d
Subject: [PATCH] Fix buggy fc() in Turkish locale
b2938d
MIME-Version: 1.0
b2938d
Content-Type: text/plain; charset=UTF-8
b2938d
Content-Transfer-Encoding: 8bit
b2938d
b2938d
When Turkish handling was added, fc() wasn't properly updated
b2938d
b2938d
Signed-off-by: Petr Písař <ppisar@redhat.com>
b2938d
---
b2938d
 pp.c      | 12 +++++++++---
b2938d
 t/op/lc.t | 23 ++++++++++++++++-------
b2938d
 2 files changed, 25 insertions(+), 10 deletions(-)
b2938d
b2938d
diff --git a/pp.c b/pp.c
b2938d
index 5e1706346d..23cc6c8adb 100644
b2938d
--- a/pp.c
b2938d
+++ b/pp.c
b2938d
@@ -4813,7 +4813,7 @@ PP(pp_fc)
b2938d
                         do {
b2938d
                             extra++;
b2938d
 
b2938d
-                            s_peek = (U8 *) memchr(s_peek + 1, 'i',
b2938d
+                            s_peek = (U8 *) memchr(s_peek + 1, 'I',
b2938d
                                                    send - (s_peek + 1));
b2938d
                         } while (s_peek != NULL);
b2938d
                     }
b2938d
@@ -4828,8 +4828,14 @@ PP(pp_fc)
b2938d
                                               + 1 /* Trailing NUL */ );
b2938d
                     d = (U8*)SvPVX(dest) + len;
b2938d
 
b2938d
-                    *d++ = UTF8_TWO_BYTE_HI(GREEK_SMALL_LETTER_MU);
b2938d
-                    *d++ = UTF8_TWO_BYTE_LO(GREEK_SMALL_LETTER_MU);
b2938d
+                    if (*s == 'I') {
b2938d
+                        *d++ = UTF8_TWO_BYTE_HI(LATIN_SMALL_LETTER_DOTLESS_I);
b2938d
+                        *d++ = UTF8_TWO_BYTE_LO(LATIN_SMALL_LETTER_DOTLESS_I);
b2938d
+                    }
b2938d
+                    else {
b2938d
+                        *d++ = UTF8_TWO_BYTE_HI(GREEK_SMALL_LETTER_MU);
b2938d
+                        *d++ = UTF8_TWO_BYTE_LO(GREEK_SMALL_LETTER_MU);
b2938d
+                    }
b2938d
                     s++;
b2938d
 
b2938d
                     for (; s < send; s++) {
b2938d
diff --git a/t/op/lc.t b/t/op/lc.t
b2938d
index fce77f3d34..812c41d6b6 100644
b2938d
--- a/t/op/lc.t
b2938d
+++ b/t/op/lc.t
b2938d
@@ -17,7 +17,7 @@ BEGIN {
b2938d
 
b2938d
 use feature qw( fc );
b2938d
 
b2938d
-plan tests => 139 + 2 * (4 * 256) + 15;
b2938d
+plan tests => 139 + 2 * (5 * 256) + 17;
b2938d
 
b2938d
 is(lc(undef),	   "", "lc(undef) is ''");
b2938d
 is(lcfirst(undef), "", "lcfirst(undef) is ''");
b2938d
@@ -352,13 +352,14 @@ foreach my $turkic (0 .. 1) {
b2938d
     my $locale = ($turkic) ? $turkic_locale : $non_turkic_locale;
b2938d
 
b2938d
   SKIP: {
b2938d
-    skip "Can't find a $type UTF-8 locale", 4*256 unless defined $locale;
b2938d
+    skip "Can't find a $type UTF-8 locale", 5*256 unless defined $locale;
b2938d
 
b2938d
     use feature qw( unicode_strings );
b2938d
 
b2938d
     no locale;
b2938d
 
b2938d
     my @unicode_lc;
b2938d
+    my @unicode_fc;
b2938d
     my @unicode_uc;
b2938d
     my @unicode_lcfirst;
b2938d
     my @unicode_ucfirst;
b2938d
@@ -366,6 +367,7 @@ foreach my $turkic (0 .. 1) {
b2938d
     # Get all the values outside of 'locale'
b2938d
     for my $i (0 .. 255) {
b2938d
         push @unicode_lc, lc(chr $i);
b2938d
+        push @unicode_fc, fc(chr $i);
b2938d
         push @unicode_uc, uc(chr $i);
b2938d
         push @unicode_lcfirst, lcfirst(chr $i);
b2938d
         push @unicode_ucfirst, ucfirst(chr $i);
b2938d
@@ -373,6 +375,7 @@ foreach my $turkic (0 .. 1) {
b2938d
 
b2938d
     if ($turkic) {
b2938d
         $unicode_lc[ord 'I'] = chr 0x131;
b2938d
+        $unicode_fc[ord 'I'] = chr 0x131;
b2938d
         $unicode_lcfirst[ord 'I'] = chr 0x131;
b2938d
         $unicode_uc[ord 'i'] = chr 0x130;
b2938d
         $unicode_ucfirst[ord 'i'] = chr 0x130;
b2938d
@@ -384,6 +387,7 @@ foreach my $turkic (0 .. 1) {
b2938d
     for my $i (0 .. 255) {
b2938d
         is(lc(chr $i), $unicode_lc[$i], "In a $type UTF-8 locale, lc(chr $i) is the same as official Unicode");
b2938d
         is(uc(chr $i), $unicode_uc[$i], "In a $type UTF-8 locale, uc(chr $i) is the same as official Unicode");
b2938d
+        is(fc(chr $i), $unicode_fc[$i], "In a $type UTF-8 locale, fc(chr $i) is the same as official Unicode");
b2938d
         is(lcfirst(chr $i), $unicode_lcfirst[$i], "In a $type UTF-8 locale, lcfirst(chr $i) is the same as official Unicode");
b2938d
         is(ucfirst(chr $i), $unicode_ucfirst[$i], "In a $type UTF-8 locale, ucfirst(chr $i) is the same as official Unicode");
b2938d
     }
b2938d
@@ -391,27 +395,32 @@ foreach my $turkic (0 .. 1) {
b2938d
 }
b2938d
 
b2938d
 SKIP: {
b2938d
-    skip "Can't find a turkic UTF-8 locale", 15 unless defined $turkic_locale;
b2938d
+    skip "Can't find a turkic UTF-8 locale", 17 unless defined $turkic_locale;
b2938d
 
b2938d
     # These are designed to stress the calculation of space needed for the
b2938d
     # strings.  $filler contains a variety of characters that have special
b2938d
     # handling in the casing functions, and some regular chars as well.
b2938d
+    # (0x49 = 'I')
b2938d
     my $filler_length = 10000;
b2938d
-    my $filler = uni_to_native("\x{df}\x{b5}\x{e0}\x{c1}\x{b6}\x{ff}") x $filler_length;
b2938d
+    my $filler = uni_to_native("\x{df}\x{49}\x{69}\x{b5}\x{e0}\x{c1}\x{b6}\x{ff}") x $filler_length;
b2938d
 
b2938d
     # These are the correct answers to what should happen when the given
b2938d
     # casing function is called on $filler;
b2938d
-    my $filler_lc = uni_to_native("\x{df}\x{b5}\x{e0}\x{e1}\x{b6}\x{ff}") x $filler_length;
b2938d
-    my $filler_fc = ("ss" . uni_to_native("\x{b5}\x{e0}\x{e1}\x{b6}\x{ff}")) x $filler_length;
b2938d
-    my $filler_uc = ("SS" . uni_to_native("\x{39c}\x{c0}\x{c1}\x{b6}\x{178}")) x $filler_length;
b2938d
+    my $filler_lc = uni_to_native("\x{df}\x{131}\x{69}\x{b5}\x{e0}\x{e1}\x{b6}\x{ff}") x $filler_length;
b2938d
+    my $filler_fc = ("ss" . uni_to_native("\x{131}\x{69}\x{3bc}\x{e0}\x{e1}\x{b6}\x{ff}")) x $filler_length;
b2938d
+    my $filler_uc = ("SS" . uni_to_native("\x{49}\x{130}\x{39c}\x{c0}\x{c1}\x{b6}\x{178}")) x $filler_length;
b2938d
 
b2938d
     use locale;
b2938d
     setlocale(&POSIX::LC_CTYPE, $turkic_locale);
b2938d
 
b2938d
     is (lc "IIIIIII$filler", "\x{131}\x{131}\x{131}\x{131}\x{131}\x{131}\x{131}$filler_lc",
b2938d
         "lc non-UTF-8, in Turkic locale, beginning with a bunch of I's");
b2938d
+    is (fc "IIIIIII$filler", "\x{131}\x{131}\x{131}\x{131}\x{131}\x{131}\x{131}$filler_fc",
b2938d
+        "fc non-UTF-8, in Turkic locale, beginning with a bunch of I's");
b2938d
     is (lc "${filler}IIIIIII$filler", "$filler_lc\x{131}\x{131}\x{131}\x{131}\x{131}\x{131}\x{131}$filler_lc",
b2938d
         "lc non-UTF-8, in Turkic locale, a bunch of I's, but not at the beginning");
b2938d
+    is (fc "${filler}IIIIIII$filler", "$filler_fc\x{131}\x{131}\x{131}\x{131}\x{131}\x{131}\x{131}$filler_fc",
b2938d
+        "fc non-UTF-8, in Turkic locale, a bunch of I's, but not at the beginning");
b2938d
     is (lc "${filler}I\x{307}$filler", "${filler_lc}i$filler_lc",
b2938d
         "lc in Turkic locale with DOT ABOVE immediately following I");
b2938d
     is (lc "${filler}I\x{307}IIIIII$filler", "${filler_lc}i\x{131}\x{131}\x{131}\x{131}\x{131}\x{131}$filler_lc",
b2938d
-- 
b2938d
2.26.2
b2938d