Skip to content

Incorrect tag attribution #855

@reandreev

Description

@reandreev

When attempting to process a GitHub Workflow, the parsing logic incorrectly (?) interprets the property on of a workflow as a boolean value. For example, taking the following workflow:

name: Workflow

on:
  push:

jobs:
  job:
    runs-on: ubuntu-latest
    steps:
      - run: echo "test"

Doing yaml.safe_load(workflow) will produce the following dict:

{
    'name': 'Workflow',
    True: {
        'push': None
    },
    'jobs': {
        'job': {
            'runs-on': 'ubuntu-latest',
            'steps': [{ 'run': 'echo "test"' }]
        }
    }
}

The key which should've been a string with value on is instead a boolean key with the value True. This happens in the resolve method, more specifically at this step:

pyyaml/lib/yaml/resolver.py

Lines 150 to 152 in 69c141a

for tag, regexp in resolvers + wildcard_resolvers:
if regexp.match(value):
return tag

where the tag tag:yaml.org,2002:bool is returned after the following regexp is matched to the value:

re.compile('^(?:yes|Yes|YES|no|No|NO\n                    |true|True|TRUE|false|False|FALSE\n                    |on|On|ON|off|Off|OFF)$', re.VERBOSE)

Any string on is converted to a boolean type which leads to this type of results. Is this intentional?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions