From 6ad42567d88fe0729a9517f793961a1d11272cf4 Mon Sep 17 00:00:00 2001 From: Jan Holthuis Date: Sat, 11 Jan 2025 01:42:07 +0100 Subject: [PATCH] fix(ofx): Use CRLF for line breaks instead of LF --- src/ofxstatement/ofx.py | 22 +++++++++++----------- src/ofxstatement/tests/test_ofx.py | 8 ++++---- src/ofxstatement/tests/test_ofx_invest.py | 6 +++--- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/ofxstatement/ofx.py b/src/ofxstatement/ofx.py index 1fb9c27..53359ab 100644 --- a/src/ofxstatement/ofx.py +++ b/src/ofxstatement/ofx.py @@ -27,19 +27,19 @@ def toxml(self, pretty: bool = False) -> str: xmlstring = etree.tostring(et.getroot(), "unicode") if pretty: dom = minidom.parseString(xmlstring) - xmlstring = dom.toprettyxml(indent=" ") + xmlstring = dom.toprettyxml(indent=" ", newl="\r\n") xmlstring = xmlstring.replace('', "").lstrip() header = ( - "OFXHEADER:100\n" - "DATA:OFXSGML\n" - "VERSION:102\n" - "SECURITY:NONE\n" - "ENCODING:UTF-8\n" - "CHARSET:NONE\n" - "COMPRESSION:NONE\n" - "OLDFILEUID:NONE\n" - "NEWFILEUID:NONE\n" - "\n" + "OFXHEADER:100\r\n" + "DATA:OFXSGML\r\n" + "VERSION:102\r\n" + "SECURITY:NONE\r\n" + "ENCODING:UTF-8\r\n" + "CHARSET:NONE\r\n" + "COMPRESSION:NONE\r\n" + "OLDFILEUID:NONE\r\n" + "NEWFILEUID:NONE\r\n" + "\r\n" ) return header + xmlstring diff --git a/src/ofxstatement/tests/test_ofx.py b/src/ofxstatement/tests/test_ofx.py index 831d977..8be1f7a 100644 --- a/src/ofxstatement/tests/test_ofx.py +++ b/src/ofxstatement/tests/test_ofx.py @@ -86,9 +86,9 @@ def prettyPrint(xmlstr: str) -> str: - headers, sep, payload = xmlstr.partition("\n\n") + headers, sep, payload = xmlstr.partition("\r\n\r\n") dom = xml.dom.minidom.parseString(payload) - pretty_payload = dom.toprettyxml(indent=" ", newl="\n").replace('\n', "") + pretty_payload = dom.toprettyxml(indent=" ", newl="\r\n").replace('\r\n', "") return headers + sep + pretty_payload @@ -113,7 +113,7 @@ def test_ofxWriter(self) -> None: # Set the generation time so it is always predictable writer.genTime = datetime(2012, 3, 3, 0, 0, 0) - assert prettyPrint(writer.toxml()) == SIMPLE_OFX.lstrip() + assert prettyPrint(writer.toxml()) == SIMPLE_OFX.lstrip().replace("\n", "\r\n") def test_ofxWriter_pretty(self) -> None: # GIVEN @@ -151,4 +151,4 @@ def test_ofxWriter_pretty(self) -> None: "", ] - assert xml.split("\n") == expected + assert xml.split("\r\n") == expected diff --git a/src/ofxstatement/tests/test_ofx_invest.py b/src/ofxstatement/tests/test_ofx_invest.py index 6608548..34013fa 100644 --- a/src/ofxstatement/tests/test_ofx_invest.py +++ b/src/ofxstatement/tests/test_ofx_invest.py @@ -160,9 +160,9 @@ def prettyPrint(xmlstr: str) -> str: - headers, sep, payload = xmlstr.partition("\n\n") + headers, sep, payload = xmlstr.partition("\r\n\r\n") dom = xml.dom.minidom.parseString(payload) - pretty_payload = dom.toprettyxml(indent=" ", newl="\n").replace('\n', "") + pretty_payload = dom.toprettyxml(indent=" ", newl="\r\n").replace('\r\n', "") return headers + sep + pretty_payload @@ -238,4 +238,4 @@ def test_ofxWriter(self) -> None: # Set the generation time so it is always predictable writer.genTime = datetime(2021, 5, 1, 0, 0, 0) - assert prettyPrint(writer.toxml()) == SIMPLE_OFX.lstrip() + assert prettyPrint(writer.toxml()) == SIMPLE_OFX.lstrip().replace("\n", "\r\n")