From 3a3625f0ae05ec93b90af756e460a7803fafd8a2 Mon Sep 17 00:00:00 2001 From: Tony Cook Date: Wed, 20 Jul 2016 14:10:44 +1000 Subject: [PATCH] (perl #128524) correct indentation for utf-8 key hash elements 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. --- dist/Data-Dumper/Dumper.xs | 4 ++-- dist/Data-Dumper/t/bugs.t | 26 +++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/dist/Data-Dumper/Dumper.xs b/dist/Data-Dumper/Dumper.xs index 8220241..0dc7699 100644 --- a/dist/Data-Dumper/Dumper.xs +++ b/dist/Data-Dumper/Dumper.xs @@ -886,7 +886,6 @@ DD_dump(pTHX_ SV *val, const char *name, STRLEN namelen, SV *retval, HV *seenhv, SV *sname; HE *entry = NULL; char *key; - STRLEN klen; SV *hval; AV *keys = NULL; @@ -976,6 +975,7 @@ DD_dump(pTHX_ SV *val, const char *name, STRLEN namelen, SV *retval, HV *seenhv, char *nkey_buffer = NULL; STRLEN nticks = 0; SV* keysv; + STRLEN klen; STRLEN keylen; STRLEN nlen; bool do_utf8 = FALSE; @@ -1029,7 +1029,7 @@ DD_dump(pTHX_ SV *val, const char *name, STRLEN namelen, SV *retval, HV *seenhv, if (style->quotekeys || key_needs_quote(key,keylen)) { if (do_utf8 || style->useqq) { STRLEN ocur = SvCUR(retval); - nlen = esc_q_utf8(aTHX_ retval, key, klen, do_utf8, style->useqq); + klen = nlen = esc_q_utf8(aTHX_ retval, key, klen, do_utf8, style->useqq); nkey = SvPVX(retval) + ocur; } else { diff --git a/dist/Data-Dumper/t/bugs.t b/dist/Data-Dumper/t/bugs.t index a440b0a..0a1ee8f 100644 --- a/dist/Data-Dumper/t/bugs.t +++ b/dist/Data-Dumper/t/bugs.t @@ -12,7 +12,7 @@ BEGIN { } use strict; -use Test::More tests => 15; +use Test::More tests => 23; use Data::Dumper; { @@ -144,4 +144,28 @@ SKIP: { &$tests; } +{ # https://rt.perl.org/Ticket/Display.html?id=128524 + my $want; + my $runtime = "runtime"; + my $requires = "requires"; + utf8::upgrade(my $uruntime = $runtime); + utf8::upgrade(my $urequires = $requires); + for my $run ($runtime, $uruntime) { + for my $req ($requires, $urequires) { + my $data = { $run => { $req => { foo => "bar" } } }; + local $Data::Dumper::Useperl = 1; + # we want them all the same + defined $want or $want = Dumper($data); + is(Dumper( $data ), $want, "utf-8 indents"); + SKIP: + { + defined &Data::Dumper::Dumpxs + or skip "No XS available", 1; + local $Data::Dumper::Useperl = 0; + is(Dumper( $data ), $want, "utf8-indents"); + } + } + } +} + # EOF -- 1.8.3.1