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