Skip to content

bug: parser does not handle "=" as a standalone token #866

@hegerdes

Description

@hegerdes

What happend

I was using pyyaml within ansible using the from_yaml_all filter to download and deserialize the prometheus CRDs but it failed on this YAML manifest:

...
properties:
  matchType:
    enum:
    - '!='
    - =  # <-- produces error
    - =~
    - '!~'
    type: string

Error:

Failed to parse multi-document YAML: could not determine a constructor for the tag 'tag:yaml.org,2002:value'
  in "<unicode string>", line 5658, column 29:
                              - =

How to reproduce:

Run this example:

import requests
import yaml

url = "https://github.com/prometheus-operator/prometheus-operator/releases/download/v0.83.0/stripped-down-crds.yaml"

# Download the spec
response = requests.get(url)
response.raise_for_status() 

# Parse multi-document YAML
documents = list(yaml.safe_load_all(response.text))
print("Parsed YAML documents:")
for i, doc in enumerate(documents, 1):
    print(f"\nDocument {i}:")
    print(doc)

Notes

I'm not sure if just having "=" as a string token is allowd by yaml spec, but other parsers handle this, so for compatibility pyyaml should probably also handle this

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