Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix loading of strings on header line with multiple spaces #172

Merged
merged 1 commit into from Apr 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 17 additions & 9 deletions lib/YAML/Loader.pm
Expand Up @@ -61,17 +61,25 @@ sub _parse {
$self->offset->[0] = -1;

if ($self->lines->[0] =~ /^---\s*(.*)$/) {
my @words = split /\s+/, $1;
my @words = split /\s/, $1;
%directives = ();
while (@words && $words[0] =~ /^#(\w+):(\S.*)$/) {
my ($key, $value) = ($1, $2);
shift(@words);
if (defined $directives{$key}) {
$self->warn('YAML_PARSE_WARN_MULTIPLE_DIRECTIVES',
$key, $self->document);
next;
while (@words) {
if ($words[0] =~ /^#(\w+):(\S.*)$/) {
my ($key, $value) = ($1, $2);
shift(@words);
if (defined $directives{$key}) {
$self->warn('YAML_PARSE_WARN_MULTIPLE_DIRECTIVES',
$key, $self->document);
next;
}
$directives{$key} = $value;
}
elsif ($words[0] eq '') {
shift @words;
}
else {
last;
}
$directives{$key} = $value;
}
$self->preface(join ' ', @words);
}
Expand Down
12 changes: 11 additions & 1 deletion test/load-tests.t
@@ -1,6 +1,6 @@
use strict;
use lib -e 't' ? 't' : 'test';
use TestYAML tests => 30;
use TestYAML tests => 32;
use Test::Deep;

run {
Expand Down Expand Up @@ -411,3 +411,13 @@ bless(do { my $x = 1; \$x}, "moose")
"test \\": 23
+++ perl
[{ 'test - ' => 23, "test ' " => 23, 'test \\' => 23 }]
=== Plain string with multiple spaces
+++ yaml
--- A B
+++ perl
'A B'
=== Plain string with multiple spaces at the beginning
+++ yaml
--- " ABC"
+++ perl
' ABC'