yaml-rust icon indicating copy to clipboard operation
yaml-rust copied to clipboard

"<<:" merge operator is not a key

Open boozook opened this issue 8 years ago • 3 comments

fn test_yaml()
{
        let s =
"
%YAML 1.2
---

defaults: &super
  a:      valueA
  b:      valueB

sub:
  <<: *super
  b:      valueB_new
  c:      valueC
";
    // load:
    let docs = YamlLoader::load_from_str(s).unwrap();
    let doc = &docs[0];
    println!("doc: {:?}", doc);

    // dump & print:
    let mut out_str = String::new();
    {
        let mut emitter = YamlEmitter::new(&mut out_str);
        emitter.dump(doc).unwrap();
    }
    println!("rerender:\n{}", out_str);
}

Current unexpected output:

rerender:
---
defaults:
  a: valueA
  b: valueB
sub:
  "<<":
    a: valueA
    b: valueB
  b: valueB_new
  c: valueC

There "<<": is a key.

boozook avatar Aug 02 '17 16:08 boozook

I agree that it would be nice to have the merge key at some point, because it is popular for defining default values.

Please note, however, that it is not part of the official YAML 1.2 specification, but an add-on to the YAML 1.1 specification defined at http://yaml.org/type/merge.html

Anyway I would not recommend using the yaml::Yaml data type at this point in time for production uses, as it is not secure.

chris-m-h avatar Aug 24 '17 19:08 chris-m-h

See https://crates.io/crates/yaml-merge-keys for an implementation of the spec.

mathstuf avatar Nov 08 '17 22:11 mathstuf

Also, this is a duplicate of #68.

mathstuf avatar Nov 08 '17 22:11 mathstuf