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

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

Open
szabgab opened this issue Oct 16, 2015 · 2 comments
Open

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

szabgab opened this issue Oct 16, 2015 · 2 comments

Comments

@szabgab
Copy link

szabgab commented Oct 16, 2015

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
Copy link
Author

szabgab commented Oct 19, 2015

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
Copy link

burak commented Nov 1, 2017

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'
                                ]
                     }
                   ]
        };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants