ingydotnet / yaml-pm

YAML Perl Module
http://search.cpan.org/dist/YAML/
20 stars 26 forks source link

YAML vs YAML::XS - : in the value #153

Open szabgab opened 8 years ago

szabgab commented 8 years ago

I found a case that YAML 1.15 parse and YAML::XS 0.59 throws exception: A minimal version is:

se 5.010;
use strict;
use warnings;

use Data::Dumper qw(Dumper);
use YAML;
use YAML::XS;

my $data = <<'END';
a:
  - b: c:
END

my $x = YAML::Load($data);
say "ok YAML $YAML::VERSION";  # YAML 1.15 parses properly
say Dumper $x; 
my $y = YAML::XS::Load($data);
say "ok YAML::XS $YAML::XS::VERSION"; # 0.59

# Following error:

# YAML::XS::Load Error: The problem:
# 
#     mapping values are not allowed in this context
# 
# was found at document: 1, line: 2, column: 9
szabgab commented 8 years ago

FYI YAML::Syck and YAML::Tiny behave like YAML::XS in this and in #152 See http://perlmaven.com/yaml-vs-yaml-xs-inconsistencies

burak commented 6 years ago

Chokes on dash as well

#!perl

use strict;
use warnings;

use YAML       ();
use YAML::XS   ();
use YAML::Syck ();
use Data::Dumper;

my $conf = <<'TEST';
---
foo:
  - bar:
    - -baz
TEST

test( $_ ) for qw(
    YAML
    YAML::XS
    YAML::Syck
);

sub test {
    my $what = shift;
    my $func = \&{ $what . '::Load' };
    eval {
        printf "%s v%s:\n", $what, $what->VERSION;
        print Dumper $func->( $conf );
        1;
    } or print "FAIL($what): $@\n";
}

output:

$ perl t.pl 
YAML v1.24:
FAIL(YAML): YAML Error: Invalid element in map
   Code: YAML_LOAD_ERR_BAD_MAP_ELEMENT
   Line: 4
   Document: 1
 at /Users/bgursoy/.plenv/versions/5.26.0/lib/perl5/site_perl/5.26.0/YAML/Loader.pm line 351.

YAML::XS v0.66:
$VAR1 = {
          'foo' => [
                     {
                       'bar' => [
                                  '-baz'
                                ]
                     }
                   ]
        };
YAML::Syck v1.30:
$VAR1 = {
          'foo' => [
                     {
                       'bar' => [
                                  '-baz'
                                ]
                     }
                   ]
        };