mirror of
https://github.com/aclindsa/ofxgo.git
synced 2024-11-22 03:30:04 -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:
parent
47f1b82c0b
commit
7834d53f9b
10
types.go
10
types.go
@ -237,6 +237,16 @@ func (ob Boolean) Equal(o Boolean) bool {
|
|||||||
|
|
||||||
type UID string
|
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
|
// The OFX specification recommends that UIDs follow the standard UUID
|
||||||
// 36-character format
|
// 36-character format
|
||||||
func (ou UID) RecommendedFormat() (bool, error) {
|
func (ou UID) RecommendedFormat() (bool, error) {
|
||||||
|
@ -250,6 +250,8 @@ func TestUnmarshalString(t *testing.T) {
|
|||||||
unmarshalHelper(t, " new
line
", &s, &overwritten)
|
unmarshalHelper(t, " new
line
", &s, &overwritten)
|
||||||
s = "Some Name"
|
s = "Some Name"
|
||||||
unmarshalHelper(t, "Some Name", &s, &overwritten)
|
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) {
|
func TestMarshalBoolean(t *testing.T) {
|
||||||
@ -264,6 +266,8 @@ func TestUnmarshalBoolean(t *testing.T) {
|
|||||||
unmarshalHelper(t, "Y", &b, &overwritten)
|
unmarshalHelper(t, "Y", &b, &overwritten)
|
||||||
b = false
|
b = false
|
||||||
unmarshalHelper(t, "N", &b, &overwritten)
|
unmarshalHelper(t, "N", &b, &overwritten)
|
||||||
|
// Make sure stray newlines are handled properly
|
||||||
|
unmarshalHelper(t, "N\n", &b, &overwritten)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMarshalUID(t *testing.T) {
|
func TestMarshalUID(t *testing.T) {
|
||||||
@ -274,6 +278,9 @@ func TestMarshalUID(t *testing.T) {
|
|||||||
func TestUnmarshalUID(t *testing.T) {
|
func TestUnmarshalUID(t *testing.T) {
|
||||||
var u, overwritten ofxgo.UID = "d1cf3d3d-9ef9-4a97-b180-81706829cb04", ""
|
var u, overwritten ofxgo.UID = "d1cf3d3d-9ef9-4a97-b180-81706829cb04", ""
|
||||||
unmarshalHelper(t, "d1cf3d3d-9ef9-4a97-b180-81706829cb04", &u, &overwritten)
|
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) {
|
func TestUIDRecommendedFormat(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user