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

support reading of properties on implicit block mapping keys

Open dota17 opened this issue 4 years ago • 5 comments

now , the following yaml document can be loaded

&anchor foo:
  foo: bar
  *anchor: duplicate key
  baz: bat
  *anchor: duplicate key

dota17 avatar Jun 30 '20 02:06 dota17

Note that the example is invalid YAML. There needs to be a space after an alias key before the colon (because a colon can be part of an anchor/alias). It should be:

  *anchor : duplicate key

perlpunk avatar Jul 25 '20 15:07 perlpunk

pyyaml parses this, however http://ben-kiki.org/ypaste/ (which is specified as reference parser) does not.

Gonna check it again later, but I think we should require a space after colon there?

rlidwka avatar Dec 01 '20 18:12 rlidwka

pyyaml and libyaml can parse it, but that is actually a bug.

perlpunk avatar Dec 01 '20 18:12 perlpunk

And what about object / array anchor merging ? Is it a valid syntax for Yaml 1.2 ?

"@figen/config-eslint@*":
  dependencies: &eslint
    "eslint": "8.55.0"
    
"@figen/config-typescript@*":
  dependencies: &typescript
    "typescript": "^5.3.3"
      
"figen@*":
  dependencies:
    << : {*eslint, *typescript}

yuriy-yarosh avatar Jan 01 '24 07:01 yuriy-yarosh

Correct would be:

<< : [*eslint, *typescript]

The syntax itself is correct. The parser doesn't know anything about << - it is just a string at this point. The constructor detects it as a merge key, and that depends on library if it allows this for YAML 1.2. It should not be enabled by default.

perlpunk avatar Jan 01 '24 12:01 perlpunk