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

[reader] Reading of properties on implicit block mapping keys.

Open dervus opened this issue 11 years ago • 4 comments

The problem is: we cannot to divide properties of a block mapping from properties of a first implicit entry in that mapping.

So, there will be an error while loading the following document:

block mapping: !!map
  !!str implicit key: some value

The reader will see block mapping: and interpret it as a block mapping. Then it will try to read properties of that mapping. That is !!map. But the reader will not stop and read !!str property of the implicit key as block mapping's property.

To be clear, there are actually three points of the failure:

  • When block collection has a property, the entry list of this collection must be separated from the properties by a line break. (implicit key is not separated from "mapping's" !!str property)
  • One node cannot have two tags. (!!map and !!str)
  • Resolving of !!str tag on a mapping will throw an error.

dervus avatar Feb 11 '13 13:02 dervus

It looks like it is only part of the problem and it is also impossible to just interpret leading tags in keys that are on the same line with the value:

!!str 16: 32

produces exception YAMLException: end of the stream or a document separator is expected at line.

Also this document

block mapping:
    !!str 16: 32

produces another kind of exception: YAMLException: bad indentation of a mapping entry.

I think that fixing handling of this two cases could resolve the issue.

ghost avatar Nov 23 '15 06:11 ghost

any chance this might get revisited? I'm guessing not given the date of the issue, but would sure be nice to support Yarn files in my license-badger project but the Yarn file my yarn install produced gives this kind of error (for dependencies here):

"@babel/[email protected]":
  version "7.12.11"
  resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.12.11.tgz#f4ad435aa263db935b8f10f2c552d23fb716a63f"
  integrity sha512-Zt1yodBx1UcyiePMSkWnU4hPqhwq7hGi2nFL1LeA3EUl+q2LQx16MISgJ0+z7dnmgvP9QtIleuETGOiOH1RcIw==
  dependencies:
    "@babel/highlight" "^7.10.4"

brettz9 avatar May 11 '21 10:05 brettz9

@brettz9, this is not a yaml file, so yaml parsers can't parse it. If you check any other yaml parser, they'd fail on it as well.

It's kinda unfortunate actually, maybe ask yarn guys to write valid yaml? All they have to do is to put : after all the keys.
Actually, they already did it in yarn v2, so nvm.

rlidwka avatar Jul 13 '21 21:07 rlidwka

I'm still running into what seems like the same issue here?

image

Here's the "bad YAML":

---
works:
  '1': 11
  !!str 2: 22
  !!str 3: 33
broken:
  !!str 1: 11
  !!str 2: 22
  !!str 3: 33

gregfenton avatar Aug 18 '23 03:08 gregfenton