Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.

Commit c82c22c

Browse files
tonycozReini Urban
authored andcommitted
Data::Dumper: correct indentation for utf-8 key hash elements
See [perl #128524] For utf-8 flagged keys the indentation was left as the default, the key length, and was not updated to the adjusted length after escaping and quoting. The test originally used a pre-rendered dump, but potentially other minor changes to the output would break that, now it simply compares against the output of the first case.
1 parent 4d1a686 commit c82c22c

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

dist/Data-Dumper/Dumper.xs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,6 @@ DD_dump(pTHX_ SV *val, const char *name, STRLEN namelen, SV *retval, HV *seenhv,
886886
SV *sname;
887887
HE *entry = NULL;
888888
char *key;
889-
STRLEN klen;
890889
SV *hval;
891890
AV *keys = NULL;
892891

@@ -976,6 +975,7 @@ DD_dump(pTHX_ SV *val, const char *name, STRLEN namelen, SV *retval, HV *seenhv,
976975
char *nkey_buffer = NULL;
977976
STRLEN nticks = 0;
978977
SV* keysv;
978+
STRLEN klen;
979979
STRLEN keylen;
980980
STRLEN nlen;
981981
bool do_utf8 = FALSE;
@@ -1029,7 +1029,7 @@ DD_dump(pTHX_ SV *val, const char *name, STRLEN namelen, SV *retval, HV *seenhv,
10291029
if (style->quotekeys || key_needs_quote(key,keylen)) {
10301030
if (do_utf8 || style->useqq) {
10311031
STRLEN ocur = SvCUR(retval);
1032-
nlen = esc_q_utf8(aTHX_ retval, key, klen, do_utf8, style->useqq);
1032+
klen = nlen = esc_q_utf8(aTHX_ retval, key, klen, do_utf8, style->useqq);
10331033
nkey = SvPVX(retval) + ocur;
10341034
}
10351035
else {

dist/Data-Dumper/t/bugs.t

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ BEGIN {
1212
}
1313

1414
use strict;
15-
use Test::More tests => 15;
15+
use Test::More tests => 23;
1616
use Data::Dumper;
1717

1818
{
@@ -144,4 +144,28 @@ SKIP: {
144144
&$tests;
145145
}
146146

147+
{ # https://rt.perl.org/Ticket/Display.html?id=128524
148+
my $want;
149+
my $runtime = "runtime";
150+
my $requires = "requires";
151+
utf8::upgrade(my $uruntime = $runtime);
152+
utf8::upgrade(my $urequires = $requires);
153+
for my $run ($runtime, $uruntime) {
154+
for my $req ($requires, $urequires) {
155+
my $data = { $run => { $req => { foo => "bar" } } };
156+
local $Data::Dumper::Useperl = 1;
157+
# we want them all the same
158+
defined $want or $want = Dumper($data);
159+
is(Dumper( $data ), $want, "utf-8 indents");
160+
SKIP:
161+
{
162+
defined &Data::Dumper::Dumpxs
163+
or skip "No XS available", 1;
164+
local $Data::Dumper::Useperl = 0;
165+
is(Dumper( $data ), $want, "utf8-indents");
166+
}
167+
}
168+
}
169+
}
170+
147171
# EOF

0 commit comments

Comments
 (0)