Skip to content

Commit

Permalink
fix some formatting and a test
Browse files Browse the repository at this point in the history
  • Loading branch information
clbanning committed Sep 16, 2020
1 parent da411ed commit b2dcb00
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
8 changes: 4 additions & 4 deletions anyxml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func TestNilMap(t *testing.T) {

func TestNilValue(t *testing.T) {
val := map[string]interface{}{"toplevel": nil}
checkval := "<root><toplevel/></root>"
checkval := "<root><toplevel><nil></toplevel></root>"

XmlDefaultEmptyElemSyntax()
xmlout, err := AnyXml(val, "root")
Expand All @@ -171,7 +171,7 @@ func TestNilValue(t *testing.T) {
}

checkval = ` <root>
<toplevel/>
<toplevel><nil></toplevel>
</root>`
xmlout, err = AnyXmlIndent(val, " ", " ", "root")
if err != nil {
Expand All @@ -183,7 +183,7 @@ func TestNilValue(t *testing.T) {
}

XmlGoEmptyElemSyntax()
checkval = "<root><toplevel></toplevel></root>"
checkval = "<root><toplevel><nil></toplevel></root>"
xmlout, err = AnyXml(val, "root")
if err != nil {
t.Fatal(err)
Expand All @@ -194,7 +194,7 @@ func TestNilValue(t *testing.T) {
}

checkval = ` <root>
<toplevel></toplevel>
<toplevel><nil></toplevel>
</root>`
xmlout, err = AnyXmlIndent(val, " ", " ", "root")
if err != nil {
Expand Down
5 changes: 2 additions & 3 deletions xml.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ var XmlCharsetReader func(charset string, input io.Reader) (io.Reader, error)
// extraneous xml.CharData will be ignored unless io.EOF is reached first.
// 3. If CoerceKeysToLower() has been called, then all key values will be lower case.
// 4. If CoerceKeysToSnakeCase() has been called, then all key values will be converted to snake case.
// 5. If DisableTrimWhiteSpace(b bool) has been called, then all values will be trimmed or not. By default
// this is true.
// 5. If DisableTrimWhiteSpace(b bool) has been called, then all values will be trimmed or not. By default
// this is true.
func NewMapXml(xmlVal []byte, cast ...bool) (Map, error) {
var r bool
if len(cast) == 1 {
Expand Down Expand Up @@ -239,7 +239,6 @@ func CoerceKeysToLower(b ...bool) {

// disableTrimWhiteSpace sets if the white space should be removed or not
var disableTrimWhiteSpace bool

var trimRunes = "\t\r\b\n "

// DisableTrimWhiteSpace set if the white space should be trimmed or not. By default white space is always trimmed. If
Expand Down
2 changes: 1 addition & 1 deletion xmlseq.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ func xmlSeqToMapParser(skey string, a []xml.Attr, p *xml.Decoder, r bool) (map[s
return n, nil
case xml.CharData:
// clean up possible noise
tt := strings.Trim(string(t.(xml.CharData)), "\t\r\b\n ")
tt := strings.Trim(string(t.(xml.CharData)), trimRunes)
if skey == "" {
// per Adrian (http://www.adrianlungu.com/) catch stray text
// in decoder stream -
Expand Down

0 comments on commit b2dcb00

Please sign in to comment.