forked from jshiffer/go-xmpp
parent
f8a24505f4
commit
d67787ca0f
11
xmpp.go
11
xmpp.go
@ -35,6 +35,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
"regexp"
|
||||||
"slices"
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -1153,6 +1154,7 @@ func (c *Client) Send(chat Chat) (n int, err error) {
|
|||||||
|
|
||||||
stanza := "<message to='%s' type='%s' id='%s' xml:lang='en'>" + subtext + "<body>%s</body>" + oobtext + thdtext + "</message>\n"
|
stanza := "<message to='%s' type='%s' id='%s' xml:lang='en'>" + subtext + "<body>%s</body>" + oobtext + thdtext + "</message>\n"
|
||||||
|
|
||||||
|
chat.Text = validUTF8(chat.Text)
|
||||||
return fmt.Fprintf(c.stanzaWriter, stanza,
|
return fmt.Fprintf(c.stanzaWriter, stanza,
|
||||||
xmlEscape(chat.Remote), xmlEscape(chat.Type), cnonce(), xmlEscape(chat.Text))
|
xmlEscape(chat.Remote), xmlEscape(chat.Type), cnonce(), xmlEscape(chat.Text))
|
||||||
}
|
}
|
||||||
@ -1534,3 +1536,12 @@ func (t tee) Read(p []byte) (n int, err error) {
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func validUTF8(s string) string {
|
||||||
|
// Remove invalid code points.
|
||||||
|
s = strings.ToValidUTF8(s, "<22>")
|
||||||
|
reg := regexp.MustCompile(`[\x{0000}-\x{0008}\x{000B}\x{000C}\x{000E}-\x{001F}]`)
|
||||||
|
s = reg.ReplaceAllString(s, "<22>")
|
||||||
|
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user