Skip to content

Commit

Permalink
handle error values (none) in xmlseq encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles Banning committed Dec 1, 2016
1 parent 59eab4e commit b3f659e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
8 changes: 6 additions & 2 deletions xmlseq.go
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,9 @@ func mapToXmlSeqIndent(doIndent bool, s *string, key string, value interface{},
}
}
i++
mapToXmlSeqIndent(doIndent, s, v.k, v.v, p)
if err := mapToXmlSeqIndent(doIndent, s, v.k, v.v, p); err != nil {
return err
}
switch v.v.(type) {
case []interface{}: // handled in []interface{} case
default:
Expand All @@ -668,7 +670,9 @@ func mapToXmlSeqIndent(doIndent bool, s *string, key string, value interface{},
if doIndent {
p.Indent()
}
mapToXmlSeqIndent(doIndent, s, key, v, p)
if err := mapToXmlSeqIndent(doIndent, s, key, v, p); err != nil {
return err
}
if doIndent {
p.Outdent()
}
Expand Down
7 changes: 4 additions & 3 deletions xmlseq_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@ func TestNewMapXmlSeq(t *testing.T) {
fmt.Println("NewMapXmlSeq, s:\n", m.StringIndent())

b, err := m.XmlIndent("", " ")
if err != nil {
t.Fatal("err:", err)
if err == nil {
fmt.Println("NewMapXmlSeq, mv.XmlIndent():\n", string(b))
t.Fatal("didn't catch invalid key: #text")
}
fmt.Println("NewMapXmlSeq, mv.XmlIndent():\n", string(b))
fmt.Println("err ok:", err)

b, err = m.XmlSeqIndent("", " ")
if err != nil {
Expand Down

0 comments on commit b3f659e

Please sign in to comment.