1
0
mirror of https://github.com/openSUSE/osc.git synced 2024-11-10 22:56:15 +01:00

Decode entities in HTTPError message body

This commit is contained in:
Andreas Schwab 2023-04-04 14:35:24 +02:00
parent 9e0d7783d6
commit b6a6ee5c00
2 changed files with 14 additions and 1 deletions

View File

@ -168,6 +168,19 @@ def xml_escape(string):
return xml.sax.saxutils.escape(string, entities=entities) return xml.sax.saxutils.escape(string, entities=entities)
def xml_unescape(string):
"""
Decode XML entities in the string.
"""
entities = {
""": "\"",
"'": "'",
}
if isinstance(string, bytes):
return xml.sax.saxutils.unescape(string.decode("utf-8"), entities=entities).encode("utf-8")
return xml.sax.saxutils.unescape(string, entities=entities)
def xml_indent(root): def xml_indent(root):
""" """
Indent XML so it looks pretty after printing or saving to file. Indent XML so it looks pretty after printing or saving to file.

View File

@ -115,7 +115,7 @@ def run(prg, argv=None):
if b'<summary>' in body: if b'<summary>' in body:
msg = body.split(b'<summary>')[1] msg = body.split(b'<summary>')[1]
msg = msg.split(b'</summary>')[0] msg = msg.split(b'</summary>')[0]
msg = _private.api.xml_escape(msg) msg = _private.api.xml_unescape(msg)
print(decode_it(msg), file=sys.stderr) print(decode_it(msg), file=sys.stderr)
if e.code >= 500 and e.code <= 599: if e.code >= 500 and e.code <= 599:
print(f'\nRequest: {e.filename}') print(f'\nRequest: {e.filename}')