Subject: | YAML::Load fails if the last value in the stream ends with '|' and there is an extra line |
Running perl, v5.8.4 built for darwin-thread-multi-2level
YAML-0.35
Summary,
If the last line of the YAML string ends with "|\n\n", then reading the string back fails. However, if the extra newline is not in the string, or if the scalar with the pipe is enclosed in quotes ('), there is no problem parsing.
[ code ]
use YAML;
$arr = ['o|'];
$str = Dump $arr;
$ok = Load $str; #works as expected
($str2 = $str) =~ s/o\|/'o|'/;
$ok2 = Load "$str2\n"; # works as well
$bad = Load "$str\n"; # fails:
# --- !perl/YAML::Error
# code: YAML_PARSE_ERR_NO_SEPARATOR
# msg: Expected separator '---'
# line: 3
# document: 2
# ...
# at test.pl line 5
I don't pretend that I've gone deeply into the code, but it looks like the easiest fix (for round-tripping, at least) is to make sure that scalars with pipes are quoted. Of course, that doesn't change the fact that load is still going to have a problem with that condition.
I think a fix might be at line 608, in sub _is_valid_implicit ("return 1 if $_[0] =~ /^\w/;"). I suspect the line should be "return 1 if $_[0] =~ /^\w+$/;"
Thank you,
Alexander Richter