Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/yaml/emitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,8 +571,8 @@ def prepare_tag_prefix(self, prefix):
chunks.append(prefix[start:end])
start = end = end+1
data = ch.encode('utf-8')
for ch in data:
chunks.append('%%%02X' % ord(ch))
for byte in data:
chunks.append('%%%02X' % byte)
if start < end:
chunks.append(prefix[start:end])
return ''.join(chunks)
Expand Down
12 changes: 12 additions & 0 deletions tests/test_emit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import io

import yaml


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

output = yaml.emit(events)

assert output == "%TAG ! tag:%002:\n---\n...\n"
assert list(yaml.parse(output))[1].tags == events[1].tags