Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty node values are resolved to an empty string ('') instead of null #119

Open
headcr4sh opened this issue May 24, 2024 · 0 comments
Open

Comments

@headcr4sh
Copy link

What's my problem?

I just recently stumbled across some weird behavior in bicep, which uses SharpYaml under the hood for it's loadYamlContent() function.

Parsing a YAML file with empty node contents yields empty strings instead of null values, which seems wrong from what I can tell.

Example

The following YAML document

toplevel:
  nested1:
  nested2: null
  nested3: ''

is parsed as:

{
  "toplevel": {
    "nested1": "",
    "nested2":null,
    "nested3":""
  }
}

I expected the value of nested1 to be null as well, though.

Excerpt from the YAML 1.2.2 specification:

YAML allows the node content to be omitted in many cases. Nodes with empty content are interpreted as if they were plain scalars with an empty value. Such nodes are commonly resolved to a “null” value.

Example 7.3: Completely Empty Flow Nodes seems to further clarify how empty node content should be resolved.

Conclusion

I tried different YAML parsers (e.g. yq, pyyaml and Go's yaml/v2 package, which is based on LibYYAML) and it seems as if most resolve empty node values to null, whereas SharpYaml seems indeed to be a notable exception when it comes to handling empty node values.

Links

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant