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