mirror of
https://salsa.debian.org/mdosch/go-sendxmpp
synced 2024-11-18 21:25:31 +00:00
Move string validation into own helper function.
This commit is contained in:
parent
679740d516
commit
dd9566eaee
11
helpers.go
11
helpers.go
@ -10,8 +10,19 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func validUTF8(s string) string {
|
||||
// Remove invalid code points.
|
||||
s = strings.ToValidUTF8(s, "")
|
||||
reg := regexp.MustCompile(`[\x{0000}-\x{0008}\x{000B}\x{000C}\x{000E}-\x{001F}]`)
|
||||
s = reg.ReplaceAllString(s, "")
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
func readFile(path string) (*bytes.Buffer, error) {
|
||||
file, err := os.Open(path)
|
||||
if err != nil {
|
||||
|
11
main.go
11
main.go
@ -12,7 +12,6 @@ import (
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@ -290,11 +289,7 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
// Remove invalid code points.
|
||||
message = strings.ToValidUTF8(message, "")
|
||||
reg := regexp.MustCompile(`[\x{0000}-\x{0008}\x{000B}\x{000C}\x{000E}-\x{001F}]`)
|
||||
message = reg.ReplaceAllString(message, "")
|
||||
|
||||
message = validUTF8(message)
|
||||
// Exit if message is empty.
|
||||
if message == "" && !*flagInteractive && !*flagListen && *flagHTTPUpload == "" {
|
||||
os.Exit(0)
|
||||
@ -428,9 +423,7 @@ func main() {
|
||||
}
|
||||
|
||||
// Remove invalid code points.
|
||||
message = strings.ToValidUTF8(message, "")
|
||||
reg := regexp.MustCompile(`[\x{0000}-\x{0008}\x{000B}\x{000C}\x{000E}-\x{001F}]`)
|
||||
message = reg.ReplaceAllString(message, "")
|
||||
message = validUTF8(message)
|
||||
if message == "" {
|
||||
continue
|
||||
}
|
||||
|
5
ox.go
5
ox.go
@ -9,7 +9,6 @@ import (
|
||||
"errors"
|
||||
"log"
|
||||
"os"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strings"
|
||||
"time"
|
||||
@ -99,9 +98,7 @@ func oxDecrypt(m xmpp.Chat, client *xmpp.Client, iqc chan xmpp.IQ,
|
||||
return "error", time.Now(), err
|
||||
}
|
||||
// Remove invalid code points.
|
||||
message := strings.ToValidUTF8(string(decryptMsg.Data), "")
|
||||
reg := regexp.MustCompile(`[\x{0000}-\x{0008}\x{000B}\x{000C}\x{000E}-\x{001F}]`)
|
||||
message = reg.ReplaceAllString(message, "")
|
||||
message := validUTF8(string(decryptMsg.Data))
|
||||
doc := etree.NewDocument()
|
||||
err = doc.ReadFromString(message)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user