mirror of
https://github.com/aclindsa/ofxgo.git
synced 2024-10-30 05:20:05 -04:00
Work around missing blank line after last header
Detect when a newline doesn't follow the last header when parsing SGML and break out of the header-parsing loop early. Add an example .qfx file demonstrating the broken behavior we're working around and a test.
This commit is contained in:
parent
7691881132
commit
0f6ceccd86
10
response.go
10
response.go
@ -35,6 +35,16 @@ type Response struct {
|
||||
func (or *Response) readSGMLHeaders(r *bufio.Reader) error {
|
||||
var seenHeader, seenVersion bool = false, false
|
||||
for {
|
||||
// Some financial institutions do not properly leave an empty line after the last header.
|
||||
// Avoid attempting to read another header in that case.
|
||||
next, err := r.Peek(1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if next[0] == '<' {
|
||||
break
|
||||
}
|
||||
|
||||
line, err := r.ReadString('\n')
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -140,10 +140,9 @@ func TestValidSamples(t *testing.T) {
|
||||
fn := func(path string, info os.FileInfo, err error) error {
|
||||
if info.IsDir() {
|
||||
return nil
|
||||
} else if filepath.Ext(path) != ".ofx" {
|
||||
} else if ext := filepath.Ext(path); ext != ".ofx" && ext != ".qfx" {
|
||||
return nil
|
||||
}
|
||||
|
||||
file, err := os.Open(path)
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected error opening %s: %s\n", path, err)
|
||||
@ -155,4 +154,5 @@ func TestValidSamples(t *testing.T) {
|
||||
return nil
|
||||
}
|
||||
filepath.Walk("samples/valid_responses", fn)
|
||||
filepath.Walk("samples/busted_responses", fn)
|
||||
}
|
||||
|
59
samples/busted_responses/bmo_v102__no_header_newline.qfx
Normal file
59
samples/busted_responses/bmo_v102__no_header_newline.qfx
Normal file
@ -0,0 +1,59 @@
|
||||
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
|
||||
<MESSAGE>OK
|
||||
</STATUS>
|
||||
<DTSERVER>20181202184906.217[-5:EDT]
|
||||
<USERKEY>SJLDF802DV09DF80
|
||||
<LANGUAGE>ENG
|
||||
<INTU.BID>00017
|
||||
</SONRS>
|
||||
</SIGNONMSGSRSV1>
|
||||
<CREDITCARDMSGSRSV1>
|
||||
<CCSTMTTRNRS>
|
||||
<TRNUID>1
|
||||
<STATUS>
|
||||
<CODE>0
|
||||
<SEVERITY>INFO
|
||||
<MESSAGE>OK
|
||||
</STATUS>
|
||||
<CCSTMTRS>
|
||||
<CURDEF>CAD
|
||||
<CCACCTFROM>
|
||||
<ACCTID>2380370270281083
|
||||
</CCACCTFROM>
|
||||
<BANKTRANLIST>
|
||||
<DTSTART>20181202184905.909[-5:EDT]
|
||||
<DTEND>20181202184905.909[-5:EDT]
|
||||
<STMTTRN>
|
||||
<TRNTYPE>CREDIT
|
||||
<DTPOSTED>20181030000000.000[-5:EDT]
|
||||
<TRNAMT>2042.24
|
||||
<FITID>2380370270281083201810302054456
|
||||
<NAME>PAYMENT RECEIVED - THANK YOU
|
||||
</STMTTRN>
|
||||
</BANKTRANLIST>
|
||||
<LEDGERBAL>
|
||||
<BALAMT>-552.63
|
||||
<DTASOF>20181202184906.217[-5:EDT]
|
||||
</LEDGERBAL>
|
||||
<AVAILBAL>
|
||||
<BALAMT>-552.63
|
||||
<DTASOF>20181202184906.217[-5:EDT]
|
||||
</AVAILBAL>
|
||||
</CCSTMTRS>
|
||||
</CCSTMTTRNRS>
|
||||
</CREDITCARDMSGSRSV1>
|
||||
</OFX>
|
Loading…
Reference in New Issue
Block a user