Skip to content

Commit

Permalink
Add support for less indented comments in block scalars
Browse files Browse the repository at this point in the history
  • Loading branch information
perlpunk committed Apr 27, 2018
1 parent 8d207bc commit f9edc91
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
16 changes: 13 additions & 3 deletions lib/YAML/Loader.pm
Original file line number Diff line number Diff line change
Expand Up @@ -702,12 +702,22 @@ sub _parse_next_line {
}

if ($type == LEAF) {
while (@{$self->lines} and
if (@{$self->lines} and
$self->lines->[0] =~ m{^( *)(\#)} and
length($1) < $offset
) {
shift @{$self->lines};
$self->{line}++;
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});
}
Expand Down
4 changes: 2 additions & 2 deletions test/load-tests.t
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,14 @@ foo : bar
- >
# Not a comment;
# Is a comment
#Not a comment
#Another comment
--- 42
#Final
#Comment
+++ 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
Expand Down

0 comments on commit f9edc91

Please sign in to comment.