For certain strings YAML::Dump() creates YAML with control characters as a plain string:
use Encode;
use Devel::Peek;
use YAML ();
use YAML::XS ();
my $binary = "\342\202\254";
my $dump = YAML::Dump($binary);
Dump $dump;
my $encoded = encode_utf8($dump);
Dump $encoded;
YAML::XS::Load($encoded);
__END__
SV = PV(0x5609b8aea0e0) at 0x5609b8b092c8
REFCNT = 1
FLAGS = (POK,IsCOW,pPOK)
PV = 0x5609b8cbc5a0 "--- \342\202\254\n"\0
CUR = 8
LEN = 10
COW_REFCNT = 0
SV = PV(0x5609b8c16030) at 0x5609b8d0a0e0
REFCNT = 1
FLAGS = (POK,IsCOW,pPOK)
PV = 0x5609b8e57930 "--- \303\242\302\202\302\254\n"\0
CUR = 11
LEN = 13
COW_REFCNT = 0
YAML::XS::Load Error: The problem:
control characters are not allowed
was found at document: 0
Strings with such characters should be quoted, and in YAML 1.1 they also need to be escaped.
For certain strings
YAML::Dump()
creates YAML with control characters as a plain string:Strings with such characters should be quoted, and in YAML 1.1 they also need to be escaped.
https://yaml.org/spec/1.1/
https://yaml.org/spec/1.2/spec.html
See also https://github.com/perlpunk/YAML-PP-p5/issues/17