1
0
mirror of https://github.com/ericchiang/pup synced 2024-11-24 08:58:08 +00:00

escape html strings

This commit is contained in:
ericchiang 2014-09-28 12:26:31 -04:00
parent 377f8f1b77
commit 40f7f533c4
2 changed files with 7 additions and 4 deletions

View File

@ -37,7 +37,8 @@ func (a AttrDisplayer) Display(nodes []*html.Node) {
attributes := node.Attr
for _, attr := range attributes {
if attr.Key == a.Attr {
fmt.Println(attr.Val)
val := html.EscapeString(attr.Val)
fmt.Printf("%s\n", val)
}
}
}

View File

@ -74,7 +74,7 @@ func (t TreeDisplayer) printIndent(level int) {
func (t TreeDisplayer) printNode(n *html.Node, level int) {
switch n.Type {
case html.TextNode:
s := n.Data
s := html.EscapeString(n.Data)
if !whitespaceRegexp.MatchString(s) {
s = preWhitespace.ReplaceAllString(s, "")
s = postWhitespace.ReplaceAllString(s, "")
@ -94,9 +94,11 @@ func (t TreeDisplayer) printNode(n *html.Node, level int) {
fmt.Print(" ")
attrKeyColor.Printf("%s", a.Key)
tokenColor.Print("=")
quoteColor.Printf(`"%s"`, a.Val)
val := html.EscapeString(a.Val)
quoteColor.Printf(`"%s"`, val)
} else {
fmt.Printf(` %s="%s"`, a.Key, a.Val)
val := html.EscapeString(a.Val)
fmt.Printf(` %s="%s"`, a.Key, val)
}
}
if printColor {