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