ingydotnet / yaml-pm

YAML Perl Module
http://search.cpan.org/dist/YAML/
20 stars 27 forks source link

The trailing NULL value changed into an empty string while loading [rt.cpan.org #82877] #131

Closed ingydotnet closed 7 years ago

ingydotnet commented 10 years ago

https://rt.cpan.org/Ticket/Display.html?id=82877

Hi. I made a patch with tests to fix this issue.
We must set the indent level correctly even if there are no more lines.

diff --git a/lib/YAML/Loader.pm b/lib/YAML/Loader.pm
index 321293d..53f4830 100644
--- a/lib/YAML/Loader.pm
+++ b/lib/YAML/Loader.pm
@@ -630,7 +630,10 @@ sub _parse_next_line {
     $self->die('YAML_EMIT_ERR_BAD_LEVEL') unless defined $offset;
     shift @{$self->lines};
     $self->eos($self->{done} = not @{$self->lines});
-    return if $self->eos;
+    if ($self->eos) {
+        $self->offset->[$level + 1] = $offset + 1;
+        return;
+    }
     $self->{line}++;

     # Determine the offset for a new leaf node
diff --git a/t/load-works.t b/t/load-works.t
index fafb931..f6dcd1c 100644
--- a/t/load-works.t
+++ b/t/load-works.t
@@ -14,3 +14,9 @@ __DATA__
 +++ yaml
 ---
 foo: bar
+=== empty hashes
++++ perl
++{foo1 => undef, foo2 => undef}
++++ yaml
+foo1:
+foo2:
perlpunk commented 7 years ago

The patch in RT looks good to me. I created a PR from it.

perlpunk commented 7 years ago

Fixed by PR/170. Thanks!!

perlpunk commented 7 years ago

released 1.20_002