1
0
mirror of https://github.com/openSUSE/osc.git synced 2024-11-13 07:56:14 +01:00

Merge pull request #1291 from andreas-schwab/master

Decode entities in HTTPError message body
This commit is contained in:
Daniel Mach 2023-04-06 09:02:10 +02:00 committed by GitHub
commit 8b5f0139e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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)
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):
"""
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:
msg = body.split(b'<summary>')[1]
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)
if e.code >= 500 and e.code <= 599:
print(f'\nRequest: {e.filename}')