a4ac56
From 7b3e03bd309fcc48a135123a60678ae2596b1c38 Mon Sep 17 00:00:00 2001
a4ac56
From: Tony Cook <tony@develop-help.com>
a4ac56
Date: Wed, 7 Jun 2017 15:00:26 +1000
a4ac56
Subject: [PATCH] clear the UTF8 flag on a glob if it isn't UTF8
a4ac56
MIME-Version: 1.0
a4ac56
Content-Type: text/plain; charset=UTF-8
a4ac56
Content-Transfer-Encoding: 8bit
a4ac56
a4ac56
Ported to 5.26.0:
a4ac56
a4ac56
commit 1097da16b21fe0a2257dba9937e55c0cca18f7e1
a4ac56
Author: Tony Cook <tony@develop-help.com>
a4ac56
Date:   Wed Jun 7 15:00:26 2017 +1000
a4ac56
a4ac56
    [perl #131263] clear the UTF8 flag on a glob if it isn't UTF8
a4ac56
a4ac56
    Previously sv_2pv_flags() would set the UTF8 flag on a glob if it
a4ac56
    had a UTF8 name, but wouldn't clear tha flag if it didn't.
a4ac56
a4ac56
    This meant a name change, eg. if assigned another glob, from a UTF8
a4ac56
    name to a non-UTF8 name would leave the flag set.
a4ac56
a4ac56
Signed-off-by: Petr Písař <ppisar@redhat.com>
a4ac56
---
a4ac56
 sv.c      |  2 ++
a4ac56
 t/op/gv.t | 10 +++++++++-
a4ac56
 2 files changed, 11 insertions(+), 1 deletion(-)
a4ac56
a4ac56
diff --git a/sv.c b/sv.c
a4ac56
index 9f3e28e..ae3dc95 100644
a4ac56
--- a/sv.c
a4ac56
+++ b/sv.c
a4ac56
@@ -3179,6 +3179,8 @@ Perl_sv_2pv_flags(pTHX_ SV *const sv, STRLEN *const lp, const I32 flags)
a4ac56
 	assert(SvPOK(buffer));
a4ac56
 	if (SvUTF8(buffer))
a4ac56
 	    SvUTF8_on(sv);
a4ac56
+        else
a4ac56
+            SvUTF8_off(sv);
a4ac56
 	if (lp)
a4ac56
 	    *lp = SvCUR(buffer);
a4ac56
 	return SvPVX(buffer);
a4ac56
diff --git a/t/op/gv.t b/t/op/gv.t
a4ac56
index 4fe6b00..670ccf6 100644
a4ac56
--- a/t/op/gv.t
a4ac56
+++ b/t/op/gv.t
a4ac56
@@ -12,7 +12,7 @@ BEGIN {
a4ac56
 
a4ac56
 use warnings;
a4ac56
 
a4ac56
-plan(tests => 280);
a4ac56
+plan(tests => 282);
a4ac56
 
a4ac56
 # type coercion on assignment
a4ac56
 $foo = 'foo';
a4ac56
@@ -1170,6 +1170,14 @@ SKIP: {
a4ac56
     is ($? & 127, 0,"[perl #128597] No crash when gp_free calls ckWARN_d");
a4ac56
 }
a4ac56
 
a4ac56
+{
a4ac56
+    # [perl #131263]
a4ac56
+    *sym = "\N{U+0080}";
a4ac56
+    ok(*sym eq "*main::\N{U+0080}", "utf8 flag properly set");
a4ac56
+    *sym = "\xC3\x80";
a4ac56
+    ok(*sym eq "*main::\xC3\x80", "utf8 flag properly cleared");
a4ac56
+}
a4ac56
+
a4ac56
 # test gv_try_downgrade()
a4ac56
 # If a GV can be stored in a stash in a compact, non-GV form, then
a4ac56
 # whenever ops are freed which reference the GV, an attempt is made to
a4ac56
-- 
a4ac56
2.9.4
a4ac56