Skip to content

Commit

Permalink
Fix import OFX file with linebreak before headers and not ASCII content
Browse files Browse the repository at this point in the history
  • Loading branch information
rennerocha committed Nov 4, 2024
1 parent 25aa800 commit b9b53b2
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 2 deletions.
3 changes: 1 addition & 2 deletions ofxparse/ofxparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,8 @@ def read_headers(self):
head_data = head_data[:head_data.find(six.b('<'))]

for line in head_data.splitlines():
# Newline?
if line.strip() == six.b(""):
break
continue

header, value = line.split(six.b(":"))
header, value = header.strip().upper(), value.strip()
Expand Down
56 changes: 56 additions & 0 deletions tests/fixtures/linebreak-before-headers-with-non-ascii-content.ofx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@

OFXHEADER:100
DATA:OFXSGML
VERSION:102
SECURITY:NONE
ENCODING:USASCII
CHARSET:1252
COMPRESSION:NONE
OLDFILEUID:NONE
NEWFILEUID:NONE

<OFX>
<SIGNONMSGSRSV1>
<SONRS>
<STATUS>
<CODE>0
<SEVERITY>INFO
</STATUS>
<DTSERVER>20240820120000
<LANGUAGE>POR
</SONRS>
</SIGNONMSGSRSV1>
<BANKMSGSRSV1>
<STMTTRNRS>
<TRNUID>1001
<STATUS>
<CODE>0
<SEVERITY>INFO
</STATUS>
<STMTRS>
<CURDEF>BRL
<BANKACCTFROM>
<BANKID>0237
<ACCTID>479984
<ACCTTYPE>CHECKING
</BANKACCTFROM>
<BANKTRANLIST>
<DTSTART>20240820120000
<DTEND>20240820120000
<STMTTRN>
<TRNTYPE>DEBIT
<DTPOSTED>20240802120000
<TRNAMT>2000,00
<FITID>N10235
<CHECKNUM>106
<MEMO>TRANSFERENCIA PIX DES: Laboratório Hacker De 18/10
</STMTTRN>
</BANKTRANLIST>
<LEDGERBAL>
<BALAMT>2000,00
<DTASOF>00000000
</LEDGERBAL>
</STMTRS>
</STMTTRNRS>
</BANKMSGSRSV1>
</OFX>
5 changes: 5 additions & 0 deletions tests/test_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,11 @@ def testMultipleAccounts(self):
self.assertEqual('CHECKING', ofx.accounts[0].account_type)
self.assertEqual('SAVINGS', ofx.accounts[1].account_type)

def test_file_linebreak_before_headers_with_non_ascii_content(self):
with open_file('linebreak-before-headers-with-non-ascii-content.ofx') as ofx_file:
ofx = OfxParser.parse(ofx_file)
self.assertEqual(len(ofx.account.statement.transactions), 1)


class TestStringToDate(TestCase):
''' Test the string to date parser '''
Expand Down

0 comments on commit b9b53b2

Please sign in to comment.