385373
From 76b7c82c2947d64a3494175ef6530b3fba8a499d Mon Sep 17 00:00:00 2001
385373
From: Zefram <zefram@fysh.org>
385373
Date: Wed, 10 Jan 2018 21:09:45 +0000
385373
Subject: [PATCH] fix Data-Dumper postentry for quoted glob
385373
MIME-Version: 1.0
385373
Content-Type: text/plain; charset=UTF-8
385373
Content-Transfer-Encoding: 8bit
385373
385373
In Data-Dumper, where a glob with a quoted name required a postentry,
385373
the name part of the postentry was being emitted as just "}".  This was
385373
an old bug affecting upgraded glob names, which the recent commit
385373
abda9fe0fe75ae824723761c1c98af958f17a41c made affect all quoted glob
385373
names.  Fix the postentry name to encompass the entire quoted name.
385373
Fixes [perl #132695].
385373
385373
Petr Písař: Ported to Data-Dumpe-2.167 from perl
385373
fb5043174b070927d312677f0a2f04a29b11349a.
385373
385373
Signed-off-by: Petr Písař <ppisar@redhat.com>
385373
---
385373
 Dumper.xs  | 11 ++++++-----
385373
 t/dumper.t | 32 +++++++++++++++++++++++++++++++-
385373
 2 files changed, 37 insertions(+), 6 deletions(-)
385373
385373
diff --git a/Dumper.xs b/Dumper.xs
385373
index 8a16e04..206e8b5 100644
385373
--- a/Dumper.xs
385373
+++ b/Dumper.xs
385373
@@ -1300,11 +1300,11 @@ 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
-		sv_grow(retval, SvCUR(retval)+2);
385373
+		sv_grow(retval, SvCUR(retval)+3);
385373
 		r = SvPVX(retval)+SvCUR(retval);
385373
-		r[0] = '*'; r[1] = '{';
385373
+		r[0] = '*'; r[1] = '{'; r[2] = 0;
385373
 		SvCUR_set(retval, SvCUR(retval)+2);
385373
-                esc_q_utf8(aTHX_ retval, c, i,
385373
+                i = 3 + esc_q_utf8(aTHX_ retval, c, i,
385373
 #ifdef GvNAMEUTF8
385373
 			!!GvNAMEUTF8(val)
385373
 #else
385373
@@ -1314,15 +1314,16 @@ DD_dump(pTHX_ SV *val, const char *name, STRLEN namelen, SV *retval, HV *seenhv,
385373
 		sv_grow(retval, SvCUR(retval)+2);
385373
 		r = SvPVX(retval)+SvCUR(retval);
385373
 		r[0] = '}'; r[1] = '\0';
385373
-		i = 1;
385373
+		SvCUR_set(retval, SvCUR(retval)+1);
385373
+		r = r+1 - i;
385373
 	    }
385373
 	    else {
385373
 		sv_grow(retval, SvCUR(retval)+i+2);
385373
 		r = SvPVX(retval)+SvCUR(retval);
385373
 		r[0] = '*'; strcpy(r+1, c);
385373
 		i++;
385373
+		SvCUR_set(retval, SvCUR(retval)+i);
385373
 	    }
385373
-	    SvCUR_set(retval, SvCUR(retval)+i);
385373
 
385373
             if (style->purity) {
385373
 		static const char* const entries[] = { "{SCALAR}", "{ARRAY}", "{HASH}" };
385373
diff --git a/t/dumper.t b/t/dumper.t
385373
index 0c12f34..e09a2dd 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 = 456;
385373
+$TMAX = 468;
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
@@ -1773,3 +1773,33 @@ EOT
385373
   TEST (q(Data::Dumper->Dumpxs([\@globs], ["globs"])), 'globs: Dumpxs()')
385373
     if $XS;
385373
 }
385373
+#############
385373
+$WANT = <<'EOT';
385373
+#$v = {
385373
+#  a => \*::ppp,
385373
+#  b => \*{'::a/b'},
385373
+#  c => \*{"::a\x{2603}b"}
385373
+#};
385373
+#*::ppp = {
385373
+#  a => 1
385373
+#};
385373
+#*{'::a/b'} = {
385373
+#  b => 3
385373
+#};
385373
+#*{"::a\x{2603}b"} = {
385373
+#  c => 5
385373
+#};
385373
+EOT
385373
+{
385373
+  *ppp = { a => 1 };
385373
+  *{"a/b"} = { b => 3 };
385373
+  *{"a\x{2603}b"} = { c => 5 };
385373
+  our $v = { a => \*ppp, b => \*{"a/b"}, c => \*{"a\x{2603}b"} };
385373
+  local $Data::Dumper::Purity = 1;
385373
+  TEST (q(Data::Dumper->Dump([$v], ["v"])), 'glob purity: Dump()');
385373
+  TEST (q(Data::Dumper->Dumpxs([$v], ["v"])), 'glob purity: Dumpxs()') if $XS;
385373
+  $WANT =~ tr/'/"/;
385373
+  local $Data::Dumper::Useqq = 1;
385373
+  TEST (q(Data::Dumper->Dump([$v], ["v"])), 'glob purity: Dump()');
385373
+  TEST (q(Data::Dumper->Dumpxs([$v], ["v"])), 'glob purity: Dumpxs()') if $XS;
385373
+}
385373
-- 
385373
2.13.6
385373