From b3f659e452cd0b2e6344a1788a472c5c0ca385d2 Mon Sep 17 00:00:00 2001 From: Charles Banning Date: Thu, 1 Dec 2016 05:09:18 -0700 Subject: [PATCH] handle error values (none) in xmlseq encoding --- xmlseq.go | 8 ++++++-- xmlseq_test.go | 7 ++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/xmlseq.go b/xmlseq.go index 985a037..22e2d27 100644 --- a/xmlseq.go +++ b/xmlseq.go @@ -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: @@ -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() } diff --git a/xmlseq_test.go b/xmlseq_test.go index 350c672..5738ba4 100644 --- a/xmlseq_test.go +++ b/xmlseq_test.go @@ -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 {