File 0153-Make-sure-to-keep-tail-in-strings-containing-emojis-.patch of Package erlang

From 52c36fa7a6a6cb81f0c068892de5b1553015e57c Mon Sep 17 00:00:00 2001
From: Christian Rasmussen <christian.rasmussen@me.com>
Date: Sat, 12 Mar 2022 00:44:44 +0100
Subject: [PATCH 2/2] Make sure to keep tail in strings containing emojis as
 well

---
 lib/stdlib/test/string_SUITE.erl           |  6 ++++++
 lib/stdlib/uc_spec/gen_unicode_mod.escript | 12 ++++++------
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/lib/stdlib/test/string_SUITE.erl b/lib/stdlib/test/string_SUITE.erl
index 2539bf8692..7d5330ddb8 100644
--- a/lib/stdlib/test/string_SUITE.erl
+++ b/lib/stdlib/test/string_SUITE.erl
@@ -652,6 +652,9 @@ cd_gc(_) ->
     [778|<<>>] = string:next_codepoint(tl(string:next_codepoint(<<$e,778/utf8>>))),
     [0|<<128,1>>] = string:next_codepoint(<<0,128,1>>),
     {error,<<128,1>>} = string:next_codepoint(<<128,1>>),
+    [128021|<<>>] = string:next_codepoint(<<128021/utf8>>), %% Dog
+    [128021|<<8205/utf8>>] = string:next_codepoint(<<128021/utf8,8205/utf8>>), %% Dog + ZWJ
+    [128021|<<8205/utf8,129466/utf8>>] = string:next_codepoint(<<128021/utf8,8205/utf8,129466/utf8>>), %% Dog + ZWJ + Service vest == Service dog
 
     [] = string:next_grapheme(""),
     [] = string:next_grapheme(<<>>),
@@ -664,6 +667,9 @@ cd_gc(_) ->
     [[$e,778]|<<>>] = string:next_grapheme(<<$e,778/utf8>>),
     [0|<<128,1>>] = string:next_grapheme(<<0,128,1>>),
     {error,<<128,1>>} = string:next_grapheme(<<128,1>>),
+    [128021|<<>>] = string:next_grapheme(<<128021/utf8>>), %% Dog
+    [[128021,8205]|<<>>] = string:next_grapheme(<<128021/utf8,8205/utf8>>), %% Dog + ZWJ
+    [[128021,8205,129466]|<<>>] = string:next_grapheme(<<128021/utf8,8205/utf8,129466/utf8>>), %% Dog + ZWJ + Service vest == Service dog
 
     ok.
 
diff --git a/lib/stdlib/uc_spec/gen_unicode_mod.escript b/lib/stdlib/uc_spec/gen_unicode_mod.escript
index af27e47337..1a5049534a 100644
--- a/lib/stdlib/uc_spec/gen_unicode_mod.escript
+++ b/lib/stdlib/uc_spec/gen_unicode_mod.escript
@@ -705,10 +705,10 @@ gen_gc(Fd, GBP) ->
                  "                _ -> [lists:reverse(Acc)|T0]\n"
                  "            end\n"
                  "    end;\n"
-                 "gc_ext_pict([], _T0, Acc) ->\n"
+                 "gc_ext_pict([], T0, Acc) ->\n"
                  "    case Acc of\n"
-                 "        [A] -> [A];\n"
-                 "        _ -> [lists:reverse(Acc)]\n"
+                 "        [A] -> [A|T0];\n"
+                 "        _ -> [lists:reverse(Acc)|T0]\n"
                  "    end;\n"
                  "gc_ext_pict({error,R}, T, Acc) ->\n"
                  "    gc_ext_pict([], T, Acc) ++ [R].\n\n"),
@@ -722,10 +722,10 @@ gen_gc(Fd, GBP) ->
                  "                _ -> [lists:reverse(Acc)|T0]\n"
                  "            end\n"
                  "    end;\n"
-                 "gc_ext_pict_zwj([], _, Acc) ->\n"
+                 "gc_ext_pict_zwj([], T0, Acc) ->\n"
                  "    case Acc of\n"
-                 "        [A] -> [A];\n"
-                 "        _ -> [lists:reverse(Acc)]\n"
+                 "        [A] -> [A|T0];\n"
+                 "        _ -> [lists:reverse(Acc)|T0]\n"
                  "    end;\n"
                  "gc_ext_pict_zwj({error,R}, T, Acc) ->\n"
                  "    gc_ext_pict_zwj([], T, Acc) ++ [R].\n\n"),
-- 
2.34.1

openSUSE Build Service is sponsored by