Skip to content

Commit

Permalink
trimming LineFeed and Tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
filariow committed Jun 14, 2019
1 parent ac52038 commit 5dec624
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion node.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (n *Node) InnerText() string {

func (n *Node) sanitizedData(preserveSpaces bool) string {
if preserveSpaces {
return n.Data
return strings.Trim(n.Data, "\n\t")
}
return strings.TrimSpace(n.Data)
}
Expand Down
21 changes: 21 additions & 0 deletions node_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package xmlquery

import (
"html"
"net/http"
"net/http/httptest"
"strings"
Expand Down Expand Up @@ -361,6 +362,11 @@ func TestOutputXMLWithSpaceParent(t *testing.T) {
if g := doc.OutputXML(true); strings.Index(g, expected) == -1 {
t.Errorf(`expected "%s", obtained "%s"`, expected, g)
}

output := html.UnescapeString(doc.OutputXML(true))
if strings.Contains(output, "\n") {
t.Errorf("the outputted xml contains newlines")
}
t.Log(n.OutputXML(false))
}

Expand All @@ -380,6 +386,11 @@ func TestOutputXMLWithSpaceDirect(t *testing.T) {
if g := doc.OutputXML(false); strings.Index(g, expected) == -1 {
t.Errorf(`expected "%s", obtained "%s"`, expected, g)
}

output := html.UnescapeString(doc.OutputXML(true))
if strings.Contains(output, "\n") {
t.Errorf("the outputted xml contains newlines")
}
t.Log(n.OutputXML(false))
}

Expand All @@ -399,6 +410,11 @@ func TestOutputXMLWithSpaceOverwrittenToPreserve(t *testing.T) {
if g := n.OutputXML(false); strings.Index(g, expected) == -1 {
t.Errorf(`expected "%s", obtained "%s"`, expected, g)
}

output := html.UnescapeString(doc.OutputXML(true))
if strings.Contains(output, "\n") {
t.Errorf("the outputted xml contains newlines")
}
t.Log(n.OutputXML(false))
}

Expand All @@ -418,5 +434,10 @@ func TestOutputXMLWithSpaceOverwrittenToDefault(t *testing.T) {
if g := doc.OutputXML(false); strings.Index(g, expected) == -1 {
t.Errorf(`expected "%s", obtained "%s"`, expected, g)
}

output := html.UnescapeString(doc.OutputXML(true))
if strings.Contains(output, "\n") {
t.Errorf("the outputted xml contains newlines")
}
t.Log(n.OutputXML(false))
}

0 comments on commit 5dec624

Please sign in to comment.