yaml icon indicating copy to clipboard operation
yaml copied to clipboard

KEY_OVER_1024_CHARS error with large indented blocks of comments

Open fluggo opened this issue 3 years ago • 4 comments

Describe the bug If there's a large block of comments hanging indented under a key, that can trigger an error suggesting that the next key indicator is too far away.

To Reproduce

const comment = `# Test comment
owners:
  # Test comment
  business:
    - email: [email protected]
      name: Moogly
    - distributionList: [email protected]

  # Another comment, large block of text, large block of text, large block of text
  # Another comment, large block of text, large block of text, large block of text
  # Another comment, large block of text, large block of text, large block of text
  # Another comment, large block of text, large block of text, large block of text
  # Another comment, large block of text, large block of text, large block of text

# Large block of text, large block of text, large block of text, large block of text, large block of text,
# large block of text, large block of text, large block of text, large block of text, large block of text,
# large block of text, large block of text, large block of text, large block of text, large block of text,
# large block of text, large block of text, large block of text, large block of text, large block of text,
# large block of text, large block of text, large block of text, large block of text, large block of text,
# large block of text, large block of text, large block of text, large block of text, large block of text,
# large block of text, large block of text, large block of text, large block of text, large block of text,
stage: one
`;

console.log(yaml.parse(comment));

The script produces the error:

YAMLParseError: The : indicator must be at most 1024 chars after the start of an implicit block mapping key at line 22, column 1:

# large block of text, large block of text, large block of text, large block of…
stage: one
^^^^^

Removing the indent from the first block of comments works around the error.

Expected behaviour The text is valid YAML, it should be parsed, no matter how many comments there are or whether they're indented.

Versions (please complete the following information):

  • Environment: Node.js 16.15.1
  • yaml: 2.1.1

fluggo avatar Sep 30 '22 21:09 fluggo

There was a bug in updating the offset during composition for empty mapping values with trailing comments. Thank you for reporting this!

Fixed version released as v2.1.2.

eemeli avatar Oct 02 '22 16:10 eemeli

Might check it against my sample again. I don't think the main bug has been fixed yet.

fluggo avatar Oct 04 '22 17:10 fluggo

Bother; you're right. I'd found first a minimal example that appeared to trigger the same error, and solved against that only.

eemeli avatar Oct 05 '22 06:10 eemeli

New fix released as 2.1.3.

@fluggo Please let me know if that actually fixes this?

eemeli avatar Oct 05 '22 07:10 eemeli

Closing as presumably fixed.

eemeli avatar Oct 26 '22 22:10 eemeli