From 4fbd7efb9173ab5e52706b388b1a88f940ecfded Mon Sep 17 00:00:00 2001 From: Martin Dosch Date: Sat, 18 Feb 2023 16:24:46 +0100 Subject: [PATCH] Make sending of OOB URLs more robust. --- helpers.go | 6 +++--- main.go | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/helpers.go b/helpers.go index e2366da..e131ca3 100644 --- a/helpers.go +++ b/helpers.go @@ -24,10 +24,10 @@ func validUTF8(s string) string { return s } -func validURI(s string) (string, error) { +func validURI(s string) (*url.URL, error) { // Check if URI is valid - _, err := url.ParseRequestURI(s) - return s, err + uri, err := url.ParseRequestURI(s) + return uri, err } func readFile(path string) (*bytes.Buffer, error) { diff --git a/main.go b/main.go index 8b10a17..9062e6f 100644 --- a/main.go +++ b/main.go @@ -396,10 +396,11 @@ func main() { // Remove invalid UTF8 code points. message = validUTF8(*flagOOBFile) // Check if the URI is valid. - _, err := validURI(message) + uri, err := validURI(message) if err != nil { log.Fatal(err) } + message = uri.String() } var msgType string @@ -545,13 +546,23 @@ func main() { break } switch { - case *flagHTTPUpload != "" || *flagOOBFile != "": + case *flagHTTPUpload != "": _, err = client.Send(xmpp.Chat{Remote: recipient.Jid, Type: msgType, Ooburl: message, Text: message}) if err != nil { fmt.Println("Couldn't send message to", recipient.Jid) } + // (Hopefully) temporary workaround due to go-xmpp choking on URL encoding. + // Once this is fixed in the lib the http-upload case above can be reused. + case *flagOOBFile != "": + _, err = client.SendOrg("" + message + "" + + message + "") + if err != nil { + fmt.Println("Couldn't send message to", + recipient.Jid) + } case *flagOx: if recipient.OxKeyRing == nil { continue