Skip to content

Node type 'PLAIN' is not respected for strings looking like numbers or boolean values #616

@edriouk

Description

@edriouk

Describe the bug
A string value which can be recognized a numeric or boolean value by the default schema s emitted with suttounding double-quotes.

To Reproduce
Create a document with a node with explicit 'PLAIN' type and stringify the document :

const yamlDoc = new YAML.Document();
const rootNode = new YAML.YAMLMap();
const hexNode = new YAML.Scalar('0x002A');
hexNode.type = Scalar.PLAIN;
rootNode.set('hex', hexNode);

const output = yamlDoc.toString(); 

The output string contains value surrounded by double quotes:
hex: "0x002A"

Expected behaviour
The output string should use plain string:
hex: 0x002A

Versions (please complete the following information):

  • Environment: Node.js v20.11.1
  • yaml: 2.7.1

Additional context
Unfortunately this incorrect behavior is even demonstrated by the regression tests for custom tags:
(tests/doc/types.ts:908)
The input is correctly parsed, but emitter output is not equal to the input: double quotes are added around values

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions