Skip to content

Hover fails with JSON parse error on YAML 1.1 boolean values (True/False/Yes/No) #1152

@lawrencetroup

Description

@lawrencetroup

Describe the bug

When hovering over YAML 1.1 boolean values like True, False, Yes, No, on, off, etc., the hover feature fails with a JSON parse error. This is a regression introduced in v1.19.0. This is seen when using the VSCode Yaml Extension (https://github.com/redhat-developer/vscode-yaml)

Error message:

Request textDocument/hover failed.
  Message: Request textDocument/hover failed with message: Unexpected token 'F', "False" is not valid JSON
  Code: -32603

Root cause: The equals() function in src/languageservice/utils/objects.ts uses JSON.parse() to convert boolean source strings, but JSON.parse() only accepts lowercase "true" or "false". YAML 1.1 accepts many boolean representations (True, False, Yes, No, yes, no, on, off, etc.) which cause the parse to fail.

This was introduced by commit e6165e4 (and 4370b5c) which fixed #1078 and #1116 by changing getNodeValue() to return node.source for booleans, but the equals() function wasn't updated to handle all YAML 1.1 boolean string formats.

Example schema:

{
  "type": "object",
  "properties": {
    "enabled": {
      "type": "boolean",
      "enum": [true, false],
      "description": "Enable or disable the feature"
    }
  }
}

Example YAML:

enabled: True

Expected Behavior

Hover should display the schema description and allowed values without error when hovering over YAML 1.1 boolean values like True, False, Yes, No, etc.

Current Behavior

The hover request fails with Unexpected token 'F', "False" is not valid JSON (or similar for other YAML 1.1 boolean representations).

Steps to Reproduce

  1. Configure yaml-language-server to use YAML 1.1 mode (yamlVersion: '1.1')

  2. Create a YAML file associated with a schema that has a boolean property with enum or const

  3. In the YAML file, use a YAML 1.1 boolean representation like enabled: True or enabled: False (capital letters) or enabled: yes/enabled: no

  4. Hover over the boolean value - the error appears

Environment

  • Linux

Additional environment details:

  • yaml-language-server version: v1.19.0+ (regression from v1.18.0)
  • vscode-yaml version: v1.19.1 (regression from v1.18.0)
  • Node.js version: 18.x

Related issues:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions