From 212fdc731bf099d17c1c4135312821d4d25293d6 Mon Sep 17 00:00:00 2001 From: John Starich Date: Fri, 14 Jun 2019 20:20:08 -0500 Subject: [PATCH] Omit end tags for encoding OFX 100-series requests Closes https://github.com/aclindsa/ofxgo/issues/18 --- bank_test.go | 26 +++++++++++++------------- leaf_elements.go | 1 + request.go | 4 ++++ request_test.go | 7 ++++--- 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/bank_test.go b/bank_test.go index f9d7b9c..389bfc7 100644 --- a/bank_test.go +++ b/bank_test.go @@ -87,29 +87,29 @@ NEWFILEUID:NONE - 20060115112300.000[-5:EST] - myusername - Pa$$word - ENG + 20060115112300.000[-5:EST] + myusername + Pa$$word + ENG - BNK - 1987 + BNK + 1987 - OFXGO - 0001 + OFXGO + 0001 - 123 + 123 - 318398732 - 78346129 - CHECKING + 318398732 + 78346129 + CHECKING - Y + Y diff --git a/leaf_elements.go b/leaf_elements.go index ef43439..a888caa 100644 --- a/leaf_elements.go +++ b/leaf_elements.go @@ -172,6 +172,7 @@ var ofxLeafElements = []string{ "IDSCOPE", "INCBAL", "INCIMAGES", + "INCLUDE", "INCOMETYPE", "INCOO", "INITIALAMT", diff --git a/request.go b/request.go index 6f6d727..4c31f9d 100644 --- a/request.go +++ b/request.go @@ -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"}} diff --git a/request_test.go b/request_test.go index d2d490d..3712f82 100644 --- a/request_test.go +++ b/request_test.go @@ -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)