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

Fix import OFX file with non-ascii characters content #178

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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