diff --git a/mellon/utils.py b/mellon/utils.py index 6462f81..1c48f1a 100644 --- a/mellon/utils.py +++ b/mellon/utils.py @@ -255,11 +255,18 @@ def login(request, user): def get_xml_encoding(content): xml_encoding = 'utf-8' + def xmlDeclHandler(version, encoding, standalone): - xml_encoding = encoding + global xml_encoding + + if encoding: + xml_encoding = encoding parser = expat.ParserCreate() parser.XmlDeclHandler = xmlDeclHandler - parser.Parse(content, True) + try: + parser.Parse(content, True) + except expat.ExpatError as e: + raise ValueError('invalid XML %s' % e) return xml_encoding diff --git a/tests/test_sso_slo.py b/tests/test_sso_slo.py index 276c373..42ab8ef 100644 --- a/tests/test_sso_slo.py +++ b/tests/test_sso_slo.py @@ -115,7 +115,7 @@ class MockIdp(object): del self.artifact_message login.buildResponseMsg() assert 'rsa-sha256' in login.msgBody - return login.msgBody + return '\n' + login.msgBody def mock_artifact_resolver(self): @all_requests