1
0
mirror of https://github.com/aclindsa/ofxgo.git synced 2024-12-26 06:53:21 -05:00

Trim spaces when unmarshalling UIDs

This ensures the correct value is parsed when SGML tags aren't closed.
Also add a test.
This commit is contained in:
Aaron Lindsay 2017-04-03 19:44:25 -04:00
parent 47f1b82c0b
commit 7834d53f9b
2 changed files with 17 additions and 0 deletions

View File

@ -237,6 +237,16 @@ func (ob Boolean) Equal(o Boolean) bool {
type UID string
func (ou *UID) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
var value string
err := d.DecodeElement(&value, &start)
if err != nil {
return err
}
*ou = UID(strings.TrimSpace(value))
return nil
}
// The OFX specification recommends that UIDs follow the standard UUID
// 36-character format
func (ou UID) RecommendedFormat() (bool, error) {

View File

@ -250,6 +250,8 @@ func TestUnmarshalString(t *testing.T) {
unmarshalHelper(t, " new
line
", &s, &overwritten)
s = "Some Name"
unmarshalHelper(t, "Some Name", &s, &overwritten)
// Make sure stray newlines are handled properly
unmarshalHelper(t, "Some Name\n", &s, &overwritten)
}
func TestMarshalBoolean(t *testing.T) {
@ -264,6 +266,8 @@ func TestUnmarshalBoolean(t *testing.T) {
unmarshalHelper(t, "Y", &b, &overwritten)
b = false
unmarshalHelper(t, "N", &b, &overwritten)
// Make sure stray newlines are handled properly
unmarshalHelper(t, "N\n", &b, &overwritten)
}
func TestMarshalUID(t *testing.T) {
@ -274,6 +278,9 @@ func TestMarshalUID(t *testing.T) {
func TestUnmarshalUID(t *testing.T) {
var u, overwritten ofxgo.UID = "d1cf3d3d-9ef9-4a97-b180-81706829cb04", ""
unmarshalHelper(t, "d1cf3d3d-9ef9-4a97-b180-81706829cb04", &u, &overwritten)
// Make sure stray newlines are handled properly
u = "0f94ce83-13b7-7568-e4fc-c02c7b47e7ab"
unmarshalHelper(t, "0f94ce83-13b7-7568-e4fc-c02c7b47e7ab\n", &u, &overwritten)
}
func TestUIDRecommendedFormat(t *testing.T) {