(perl #128524) correct indentation for utf-8 key hash elements
authorTony Cook <tony@develop-help.com>
Wed, 20 Jul 2016 04:10:44 +0000 (14:10 +1000)
committerTony Cook <tony@develop-help.com>
Wed, 20 Jul 2016 04:10:44 +0000 (14:10 +1000)
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
dist/Data-Dumper/t/bugs.t

index 8220241..0dc7699 100644 (file)
@@ -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 {
index a440b0a..0a1ee8f 100644 (file)
@@ -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