Skip to content

TypeError raised from ord() call in yaml.emit #862

Description

@gabe-sherman

The below code results in a TypeError: ord() expected string of length 1, but int found when yaml.emit is called. This occurs in the function prepare_tag_prefix at line 575 in emitter.py.

Minimized Reproducer:

import io
import yaml

text = io.BytesIO( b"%TAG ! tag:%002:\n---")
events = list(yaml.parse(text))
output = yaml.emit(events)

Version Information:

7.0.0.dev0
also occurs in the current release: 6.0.2

Exception Trace:

  File "/rep.py", line 6, in <module>
    output = yaml.emit(events)
  File "lib/python3.9/site-packages/yaml/__init__.py", line 172, in emit
    dumper.emit(event)
  File "lib/python3.9/site-packages/yaml/emitter.py", line 115, in emit
    self.state()
  File "lib/python3.9/site-packages/yaml/emitter.py", line 176, in expect_first_document_start
    return self.expect_document_start(first=True)
  File "lib/python3.9/site-packages/yaml/emitter.py", line 193, in expect_document_start
    prefix_text = self.prepare_tag_prefix(prefix)
  File "lib/python3.9/site-packages/yaml/emitter.py", line 575, in prepare_tag_prefix
    chunks.append('%%%02X' % ord(ch))
TypeError: ord() expected string of length 1, but int found

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions