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