385373
From 69beb4272d324bb0724b140b5ddca517e90d89b9 Mon Sep 17 00:00:00 2001
385373
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
385373
Date: Tue, 5 Dec 2017 10:59:42 +0100
385373
Subject: [PATCH] in Data-Dumper, quote glob names better
385373
MIME-Version: 1.0
385373
Content-Type: text/plain; charset=UTF-8
385373
Content-Transfer-Encoding: 8bit
385373
385373
Ported to Data-Dumper-1.167 from perl git tree:
385373
385373
commit abda9fe0fe75ae824723761c1c98af958f17a41c
385373
Author: Zefram <zefram@fysh.org>
385373
Date:   Fri Dec 1 17:35:35 2017 +0000
385373
385373
    in Data-Dumper, quote glob names better
385373
385373
    Glob name quoting should obey Useqq.  Fixes [perl #119831].
385373
385373
Signed-off-by: Petr Písař <ppisar@redhat.com>
385373
---
385373
 Dumper.pm  |  4 ++--
385373
 Dumper.xs  | 22 +++++++---------------
385373
 t/dumper.t | 35 ++++++++++++++++++++++++++++++++++-
385373
 3 files changed, 43 insertions(+), 18 deletions(-)
385373
385373
diff --git a/Dumper.pm b/Dumper.pm
385373
index 00f6326..696964a 100644
385373
--- a/Dumper.pm
385373
+++ b/Dumper.pm
385373
@@ -527,8 +527,8 @@ sub _dump {
385373
     $ref = \$val;
385373
     if (ref($ref) eq 'GLOB') {  # glob
385373
       my $name = substr($val, 1);
385373
-      if ($name =~ /^[A-Za-z_][\w:]*$/ && $name ne 'main::') {
385373
-        $name =~ s/^main::/::/;
385373
+      $name =~ s/^main::(?!\z)/::/;
385373
+      if ($name =~ /\A(?:[A-Z_a-z][0-9A-Z_a-z]*)?::(?:[0-9A-Z_a-z]+::)*[0-9A-Z_a-z]*\z/ && $name ne 'main::') {
385373
         $sname = $name;
385373
       }
385373
       else {
385373
diff --git a/Dumper.xs b/Dumper.xs
385373
index 5a21721..8a16e04 100644
385373
--- a/Dumper.xs
385373
+++ b/Dumper.xs
385373
@@ -1300,29 +1300,21 @@ DD_dump(pTHX_ SV *val, const char *name, STRLEN namelen, SV *retval, HV *seenhv,
385373
 		    i = 0; else i -= 4;
385373
 	    }
385373
             if (globname_needs_quote(c,i)) {
385373
-#ifdef GvNAMEUTF8
385373
-	      if (GvNAMEUTF8(val)) {
385373
 		sv_grow(retval, SvCUR(retval)+2);
385373
 		r = SvPVX(retval)+SvCUR(retval);
385373
 		r[0] = '*'; r[1] = '{';
385373
 		SvCUR_set(retval, SvCUR(retval)+2);
385373
-                esc_q_utf8(aTHX_ retval, c, i, 1, style->useqq);
385373
+                esc_q_utf8(aTHX_ retval, c, i,
385373
+#ifdef GvNAMEUTF8
385373
+			!!GvNAMEUTF8(val)
385373
+#else
385373
+			0
385373
+#endif
385373
+			, style->useqq);
385373
 		sv_grow(retval, SvCUR(retval)+2);
385373
 		r = SvPVX(retval)+SvCUR(retval);
385373
 		r[0] = '}'; r[1] = '\0';
385373
 		i = 1;
385373
-	      }
385373
-	      else
385373
-#endif
385373
-	      {
385373
-		sv_grow(retval, SvCUR(retval)+6+2*i);
385373
-		r = SvPVX(retval)+SvCUR(retval);
385373
-		r[0] = '*'; r[1] = '{';	r[2] = '\'';
385373
-		i += esc_q(r+3, c, i);
385373
-		i += 3;
385373
-		r[i++] = '\''; r[i++] = '}';
385373
-		r[i] = '\0';
385373
-	      }
385373
 	    }
385373
 	    else {
385373
 		sv_grow(retval, SvCUR(retval)+i+2);
385373
diff --git a/t/dumper.t b/t/dumper.t
385373
index 643160a..0c12f34 100644
385373
--- a/t/dumper.t
385373
+++ b/t/dumper.t
385373
@@ -108,7 +108,7 @@ sub SKIP_TEST {
385373
   ++$TNUM; print "ok $TNUM # skip $reason\n";
385373
 }
385373
 
385373
-$TMAX = 450;
385373
+$TMAX = 456;
385373
 
385373
 # Force Data::Dumper::Dump to use perl. We test Dumpxs explicitly by calling
385373
 # it direct. Out here it lets us knobble the next if to test that the perl
385373
@@ -1740,3 +1740,36 @@ EOT
385373
         TEST (qq(Dumper("\n")), '\n alone');
385373
         TEST (qq(Data::Dumper::DumperX("\n")), '\n alone') if $XS;
385373
 }
385373
+#############
385373
+our @globs = map { $_, \$_ } map { *$_ } map { $_, "s::$_" }
385373
+		"foo", "\1bar", "L\x{e9}on", "m\x{100}cron", "snow\x{2603}";
385373
+$WANT = <<'EOT';
385373
+#$globs = [
385373
+#  *::foo,
385373
+#  \*::foo,
385373
+#  *s::foo,
385373
+#  \*s::foo,
385373
+#  *{"::\1bar"},
385373
+#  \*{"::\1bar"},
385373
+#  *{"s::\1bar"},
385373
+#  \*{"s::\1bar"},
385373
+#  *{"::L\351on"},
385373
+#  \*{"::L\351on"},
385373
+#  *{"s::L\351on"},
385373
+#  \*{"s::L\351on"},
385373
+#  *{"::m\x{100}cron"},
385373
+#  \*{"::m\x{100}cron"},
385373
+#  *{"s::m\x{100}cron"},
385373
+#  \*{"s::m\x{100}cron"},
385373
+#  *{"::snow\x{2603}"},
385373
+#  \*{"::snow\x{2603}"},
385373
+#  *{"s::snow\x{2603}"},
385373
+#  \*{"s::snow\x{2603}"}
385373
+#];
385373
+EOT
385373
+{
385373
+  local $Data::Dumper::Useqq = 1;
385373
+  TEST (q(Data::Dumper->Dump([\@globs], ["globs"])), 'globs: Dump()');
385373
+  TEST (q(Data::Dumper->Dumpxs([\@globs], ["globs"])), 'globs: Dumpxs()')
385373
+    if $XS;
385373
+}
385373
-- 
385373
2.13.6
385373