From 6b062fa867439361d5a3a2dbc125c06acf2030a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tina=20M=C3=BCller?= Date: Sun, 19 Feb 2017 01:17:32 +0100 Subject: [PATCH] Add support for less indented comments in block scalars --- lib/YAML/Loader.pm | 19 +++++++++++++------ test/load-tests.t | 2 +- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/YAML/Loader.pm b/lib/YAML/Loader.pm index 1d45fa0..f78e265 100644 --- a/lib/YAML/Loader.pm +++ b/lib/YAML/Loader.pm @@ -701,12 +701,19 @@ sub _parse_next_line { } if ($type == LEAF) { - while (@{$self->lines} and - $self->lines->[0] =~ m{^( *)(\#)} and - length($1) < $offset - ) { - shift @{$self->lines}; - $self->{line}++; + if (@{$self->lines} and $self->lines->[0] =~ m{^( *)(\#)}) { + if ( length($1) < $offset) { + shift @{$self->lines}; + $self->{line}++; + # every comment after that is also thrown away regardless + # of identation + while (@{$self->lines} and + $self->lines->[0] =~ m{^( *)(\#)} + ) { + shift @{$self->lines}; + $self->{line}++; + } + } } $self->eos($self->{done} = not @{$self->lines}); } diff --git a/test/load-tests.t b/test/load-tests.t index a939262..25414fa 100644 --- a/test/load-tests.t +++ b/test/load-tests.t @@ -218,7 +218,7 @@ foo : bar +++ perl ([2,3,4,5], {foo => 'bar', boo => 'far'}, - ["# Not a comment; #Not a comment\n"], + ["# Not a comment;\n"], 42) === several docs, some empty +++ yaml