ingydotnet / yaml-libyaml-pm

Perl Binding to libyaml
http://search.cpan.org/dist/YAML-LibYAML/
33 stars 37 forks source link

Load() and utf8.pm don't play nice. (RT54683) #15

Closed nawglan closed 8 years ago

nawglan commented 9 years ago

The attached program demonstrates utf8 and YAML::XS don't mix.

#!/usr/bin/perl

use utf8;
use YAML::XS qw(Load);

my $yaml =q[
Ævar Arnfjörð Bjarmason:
  - avar@cpan.org
  - avarab@gmail.com
];

Load($yaml);
print "Done\n";

I get:

YAML::XS::Load Error: The problem:

    Invalid trailing UTF-8 octet

was found at document: 0

With a wide character, like so:

my $yaml =q[
貞廣知行:
  - bqw10602@nifty.com
];

I get: Wide character in subroutine entry at yourfile line 11.

edit @perlpunk 2016-07-02: marked code sections

perlpunk commented 8 years ago

YAML::XS wants encoded strings. use utf8 automatically decodes strings inside of the script, so if you feed those to Load, you have to encode it again first.

Load(encode_utf8 $yaml);

So I'm closing this issue, but feel free to reopen if necessary.