Skip to content

Commit

Permalink
fix(ofx): Use CRLF for line breaks instead of LF
Browse files Browse the repository at this point in the history
  • Loading branch information
Holzhaus committed Jan 12, 2025
1 parent 9536ec7 commit 6ad4256
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
22 changes: 11 additions & 11 deletions src/ofxstatement/ofx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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('<?xml version="1.0" ?>', "").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
Expand Down
8 changes: 4 additions & 4 deletions src/ofxstatement/tests/test_ofx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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('<?xml version="1.0" ?>\n', "")
pretty_payload = dom.toprettyxml(indent=" ", newl="\r\n").replace('<?xml version="1.0" ?>\r\n', "")
return headers + sep + pretty_payload


Expand All @@ -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
Expand Down Expand Up @@ -151,4 +151,4 @@ def test_ofxWriter_pretty(self) -> None:
"",
]

assert xml.split("\n") == expected
assert xml.split("\r\n") == expected
6 changes: 3 additions & 3 deletions src/ofxstatement/tests/test_ofx_invest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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('<?xml version="1.0" ?>\n', "")
pretty_payload = dom.toprettyxml(indent=" ", newl="\r\n").replace('<?xml version="1.0" ?>\r\n', "")
return headers + sep + pretty_payload


Expand Down Expand Up @@ -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")

0 comments on commit 6ad4256

Please sign in to comment.