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