forked from jshiffer/go-xmpp
Move to xml.Escape()
This commit is contained in:
parent
d0cdb99fae
commit
3e4f4a3a80
18
xmpp.go
18
xmpp.go
@ -901,24 +901,10 @@ func next(p *xml.Decoder) (xml.Name, interface{}, error) {
|
|||||||
return se.Name, nv, err
|
return se.Name, nv, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var xmlSpecial = map[byte]string{
|
|
||||||
'<': "<",
|
|
||||||
'>': ">",
|
|
||||||
'"': """,
|
|
||||||
'\'': "'",
|
|
||||||
'&': "&",
|
|
||||||
}
|
|
||||||
|
|
||||||
func xmlEscape(s string) string {
|
func xmlEscape(s string) string {
|
||||||
var b bytes.Buffer
|
var b bytes.Buffer
|
||||||
for i := 0; i < len(s); i++ {
|
xml.Escape(&b, []byte(s))
|
||||||
c := s[i]
|
|
||||||
if s, ok := xmlSpecial[c]; ok {
|
|
||||||
b.WriteString(s)
|
|
||||||
} else {
|
|
||||||
b.WriteByte(c)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return b.String()
|
return b.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user