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>
<SIGNONMSGSRQV1>
<SONRQ>
<DTCLIENT>20060115112300.000[-5:EST]</DTCLIENT>
<USERID>myusername</USERID>
<USERPASS>Pa$$word</USERPASS>
<LANGUAGE>ENG</LANGUAGE>
<DTCLIENT>20060115112300.000[-5:EST]
<USERID>myusername
<USERPASS>Pa$$word
<LANGUAGE>ENG
<FI>
<ORG>BNK</ORG>
<FID>1987</FID>
<ORG>BNK
<FID>1987
</FI>
<APPID>OFXGO</APPID>
<APPVER>0001</APPVER>
<APPID>OFXGO
<APPVER>0001
</SONRQ>
</SIGNONMSGSRQV1>
<BANKMSGSRQV1>
<STMTTRNRQ>
<TRNUID>123</TRNUID>
<TRNUID>123
<STMTRQ>
<BANKACCTFROM>
<BANKID>318398732</BANKID>
<ACCTID>78346129</ACCTID>
<ACCTTYPE>CHECKING</ACCTTYPE>
<BANKID>318398732
<ACCTID>78346129
<ACCTTYPE>CHECKING
</BANKACCTFROM>
<INCTRAN>
<INCLUDE>Y</INCLUDE>
<INCLUDE>Y
</INCTRAN>
</STMTRQ>
</STMTTRNRQ>

View File

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

View File

@ -90,6 +90,10 @@ func (oq *Request) Marshal() (*bytes.Buffer, error) {
if oq.carriageReturn {
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"}}

View File

@ -7,7 +7,8 @@ import (
"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) {
t.Helper()
@ -18,8 +19,8 @@ func marshalCheckRequest(t *testing.T, request *ofxgo.Request, expected string)
actualString := buf.String()
// Ignore spaces between XML elements
expectedString := ignoreSpacesRe.ReplaceAllString(expected, "><")
actualString = ignoreSpacesRe.ReplaceAllString(actualString, "><")
expectedString := ignoreSpacesRe.ReplaceAllString(expected, "")
actualString = ignoreSpacesRe.ReplaceAllString(actualString, "")
if expectedString != actualString {
compareLength := len(expectedString)