~emersion/soju-dev

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
1

[PATCH v2] Make sure that WebSocket messages are valid UTF-8

Details
Message ID
<20200902150617.119576-1-hubert@hirtzfr.eu>
DKIM signature
pass
Download raw message
Patch: +3 -1
... by replacing invalid bytes with the REPLACEMENT CHARACTER U+FFFD

This is better than:
- discarding the whole message, since the user would not see it...
- removing invalid bytes, since the user would not see their presence,
- converting the encoding (this is actually not possible).

Contrary to its documentation, strings.ToValidUTF8 doesn't copy the
string if it's valid UTF-8:
<https://golang.org/src/strings/strings.go?s=15815:15861#L623>
---
 conn.go | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/conn.go b/conn.go
index 6914179..c14f13e 100644
--- a/conn.go
+++ b/conn.go
@@ -5,8 +5,10 @@ import (
	"fmt"
	"io"
	"net"
	"strings"
	"sync"
	"time"
	"unicode"

	"gopkg.in/irc.v3"
	"nhooyr.io/websocket"
@@ -62,7 +64,7 @@ func (wic websocketIRCConn) ReadMessage() (*irc.Message, error) {
}

func (wic websocketIRCConn) WriteMessage(msg *irc.Message) error {
	b := []byte(msg.String())
	b := []byte(strings.ToValidUTF8(msg.String(), string(unicode.ReplacementChar)))
	ctx := context.Background()
	if !wic.writeDeadline.IsZero() {
		var cancel context.CancelFunc
-- 
2.28.0
Details
Message ID
<Ze0JGuC_XcYYpVARrhPzv4ou_N62hI-zeb6QFytlYnGRC7urOo9ZOw1btUi2CMuq0sJC0daCsfTRZbeIZg7vWAgivJARx626AG74xdxG8gA=@emersion.fr>
In-Reply-To
<20200902150617.119576-1-hubert@hirtzfr.eu> (view parent)
DKIM signature
fail
Download raw message
DKIM signature: fail
LGTM and pushed, thanks!
Review patch Export thread (mbox)