ingydotnet / yaml-libyaml-pm

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

No error for duplicate keys. (RT80480) #17

Closed nawglan closed 2 years ago

nawglan commented 9 years ago

According to the yaml spec, duplicates should be treated as errors. But even in the latest version of YAML-LibYAML(0.38) there is no error for duplicate keys.

example:

Following is the content of an .yaml file:

student : 
 - name : Tommy
   mobile : 04567890
   age : 19 # (in years)
   contacts :
    -  type : email
       name : tommy@yahoo.com

student : 
 - name : Fommy
   mobile : 13456890
   age : 20 # (in years)
   contacts :
    -  type : email
       name : fommy@outlook.com

Now if the content of the above file is loaded using the function 'load', then only last section is coming. Each one is being overwritten by its successor section. So after 'load' we are getting only following:

student : 
 - name : Fommy
   mobile : 13456890
   age : 20 # (in years)
   contacts :
    -  type : email
       name : fommy@yahoo.com

But we should get an error here because of the duplicate key ('student').

pangyre commented 2 years ago

Bump. This would be a great to have.

perlpunk commented 2 years ago

I created #105

pangyre commented 2 years ago

Thank you for looking at this!

perlpunk commented 2 years ago

https://metacpan.org/release/TINITA/YAML-LibYAML-0.84 released, so now you can set $YAML::XS::ForbidDuplicateKeys = 1