Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[12.0] FIX import XML with invalid URI #911

Merged
merged 2 commits into from
Feb 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion l10n_it_fatturapa/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

{
'name': 'Italian Localization - Fattura elettronica - Base',
'version': '12.0.1.2.2',
'version': '12.0.1.2.3',
'category': 'Localization/Italy',
'summary': 'Fatture elettroniche',
'author': 'Davide Corio, Agile Business Group, Innoviu, '
Expand Down
15 changes: 12 additions & 3 deletions l10n_it_fatturapa/models/ir_attachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,23 @@ def decrypt_to_xml(self, signed_file, xml_file):
return xml_file

def remove_xades_sign(self, xml):
root = ET.XML(xml)
# Recovering parser is needed for files where strings like
# xmlns:ds="http://www.w3.org/2000/09/xmldsig#""
# are present: even if lxml raises
# {XMLSyntaxError}xmlns:ds:
# 'http://www.w3.org/2000/09/xmldsig#"' is not a valid URI
# such files are accepted by SDI
recovering_parser = ET.XMLParser(recover=True)
root = ET.XML(xml, parser=recovering_parser)
for elem in root.iter('*'):
if elem.tag.find('Signature') > -1:
elem.getparent().remove(elem)
break
return ET.tostring(root)

def strip_xml_content(self, xml):
root = ET.XML(xml)
recovering_parser = ET.XMLParser(recover=True)
root = ET.XML(xml, parser=recovering_parser)
for elem in root.iter('*'):
if elem.text is not None:
elem.text = elem.text.strip()
Expand Down Expand Up @@ -168,7 +176,8 @@ def get_fattura_elettronica_preview(self):
xslt = ET.parse(xsl_path)
xml_string = self.get_xml_string()
xml_file = BytesIO(xml_string)
dom = ET.parse(xml_file)
recovering_parser = ET.XMLParser(recover=True)
dom = ET.parse(xml_file, parser=recovering_parser)
transform = ET.XSLT(xslt)
newdom = transform(dom)
return ET.tostring(newdom, pretty_print=True)
2 changes: 1 addition & 1 deletion l10n_it_fatturapa_in/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

{
'name': 'Italian Localization - Fattura elettronica - Ricezione',
'version': '12.0.1.1.1',
'version': '12.0.1.1.2',
"development_status": "Beta",
'category': 'Localization/Italy',
'summary': 'Ricezione fatture elettroniche',
Expand Down
2 changes: 1 addition & 1 deletion l10n_it_fatturapa_in/tests/data/IT02780790107_11004.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<p:FatturaElettronica versione="FPA12" xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
<p:FatturaElettronica versione="FPA12" xmlns:ds="http://www.w3.org/2000/09/xmldsig#&quot;"
xmlns:p="http://ivaservizi.agenziaentrate.gov.it/docs/xsd/fatture/v1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ivaservizi.agenziaentrate.gov.it/docs/xsd/fatture/v1.2 http://www.fatturapa.gov.it/export/fatturazione/sdi/fatturapa/v1.2/Schema_del_file_xml_FatturaPA_versione_1.2.xsd">
Expand Down