-
Notifications
You must be signed in to change notification settings - Fork 315
Description
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: TrueExpected 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
-
Configure yaml-language-server to use YAML 1.1 mode (
yamlVersion: '1.1') -
Create a YAML file associated with a schema that has a boolean property with
enumorconst -
In the YAML file, use a YAML 1.1 boolean representation like
enabled: Trueorenabled: False(capital letters) orenabled: yes/enabled: no -
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:
- Using
boolvalues inenumandconstgenerates a validation error for valid values #1078 - Using bool values in enum and const generates a validation error for valid values - QuickFix not rendering on number/integer allowed values #1116 - Validation shows false negative errors if using boolean with const