1
0
mirror of https://github.com/aclindsa/ofxgo.git synced 2024-11-21 11:20:04 -05:00

Omit end tags for encoding OFX 100-series requests

Closes https://github.com/aclindsa/ofxgo/issues/18
This commit is contained in:
John Starich 2019-06-14 20:20:08 -05:00 committed by Aaron Lindsay
parent 66dd37781f
commit 212fdc731b
4 changed files with 22 additions and 16 deletions

View File

@ -87,29 +87,29 @@ NEWFILEUID:NONE
<OFX> <OFX>
<SIGNONMSGSRQV1> <SIGNONMSGSRQV1>
<SONRQ> <SONRQ>
<DTCLIENT>20060115112300.000[-5:EST]</DTCLIENT> <DTCLIENT>20060115112300.000[-5:EST]
<USERID>myusername</USERID> <USERID>myusername
<USERPASS>Pa$$word</USERPASS> <USERPASS>Pa$$word
<LANGUAGE>ENG</LANGUAGE> <LANGUAGE>ENG
<FI> <FI>
<ORG>BNK</ORG> <ORG>BNK
<FID>1987</FID> <FID>1987
</FI> </FI>
<APPID>OFXGO</APPID> <APPID>OFXGO
<APPVER>0001</APPVER> <APPVER>0001
</SONRQ> </SONRQ>
</SIGNONMSGSRQV1> </SIGNONMSGSRQV1>
<BANKMSGSRQV1> <BANKMSGSRQV1>
<STMTTRNRQ> <STMTTRNRQ>
<TRNUID>123</TRNUID> <TRNUID>123
<STMTRQ> <STMTRQ>
<BANKACCTFROM> <BANKACCTFROM>
<BANKID>318398732</BANKID> <BANKID>318398732
<ACCTID>78346129</ACCTID> <ACCTID>78346129
<ACCTTYPE>CHECKING</ACCTTYPE> <ACCTTYPE>CHECKING
</BANKACCTFROM> </BANKACCTFROM>
<INCTRAN> <INCTRAN>
<INCLUDE>Y</INCLUDE> <INCLUDE>Y
</INCTRAN> </INCTRAN>
</STMTRQ> </STMTRQ>
</STMTTRNRQ> </STMTTRNRQ>

View File

@ -172,6 +172,7 @@ var ofxLeafElements = []string{
"IDSCOPE", "IDSCOPE",
"INCBAL", "INCBAL",
"INCIMAGES", "INCIMAGES",
"INCLUDE",
"INCOMETYPE", "INCOMETYPE",
"INCOO", "INCOO",
"INITIALAMT", "INITIALAMT",

View File

@ -90,6 +90,10 @@ func (oq *Request) Marshal() (*bytes.Buffer, error) {
if oq.carriageReturn { if oq.carriageReturn {
encoder.CarriageReturn(true) encoder.CarriageReturn(true)
} }
if oq.Version < OfxVersion200 {
// OFX 100 series versions should avoid element close tags for compatibility
encoder.SetDisableAutoClose(ofxLeafElements...)
}
ofxElement := xml.StartElement{Name: xml.Name{Local: "OFX"}} ofxElement := xml.StartElement{Name: xml.Name{Local: "OFX"}}

View File

@ -7,7 +7,8 @@ import (
"testing" "testing"
) )
var ignoreSpacesRe = regexp.MustCompile(">[ \t\r\n]+<") // match leading and trailing whitespace on each line
var ignoreSpacesRe = regexp.MustCompile("(?m)^[ \t]+|[ \t]*$[\r\n]+")
func marshalCheckRequest(t *testing.T, request *ofxgo.Request, expected string) { func marshalCheckRequest(t *testing.T, request *ofxgo.Request, expected string) {
t.Helper() t.Helper()
@ -18,8 +19,8 @@ func marshalCheckRequest(t *testing.T, request *ofxgo.Request, expected string)
actualString := buf.String() actualString := buf.String()
// Ignore spaces between XML elements // Ignore spaces between XML elements
expectedString := ignoreSpacesRe.ReplaceAllString(expected, "><") expectedString := ignoreSpacesRe.ReplaceAllString(expected, "")
actualString = ignoreSpacesRe.ReplaceAllString(actualString, "><") actualString = ignoreSpacesRe.ReplaceAllString(actualString, "")
if expectedString != actualString { if expectedString != actualString {
compareLength := len(expectedString) compareLength := len(expectedString)