Note: There are a few cases of duplicates in user autocompletion which are being worked on.

Convert invalid UTF-16 to UTF-8 in websocket send()

RESOLVED FIXED in mozilla16



Networking: WebSockets
5 years ago
5 years ago


(Reporter: jduell, Assigned: jduell)



Firefox Tracking Flags

(Not tracked)



(1 attachment)

The W3C Candidate Recommendation 08 December 2011 says we should throw an exception if text with unpaired surrogates is passed to send().  The latest editor's draft has changed that to say that we should convert the incoming argument to Unicode if it's not already (I'm an ignoramus about Unicode: apparently this involves inserting replacement characters).

Not sure when we should ship a fix:  now, or wait until the Editor's draft becomes another W3C recommendation?
Summary: Convert invalid UTF-8 to UTF-8 in websocket send() → Convert invalid UTF-16 to UTF-8 in websocket send()
Consensus in the working group was to take this change (though it came down to a close vote if we should make the change now or wait until v2 of the protocol). So I feel pretty confident that this change will stick, so I see no reason to wait.

Comment 2

5 years ago
Created attachment 638996 [details] [diff] [review]
v1 fix

Why do I ever think little things like this will take "just 15 minutes"? 

Anyway:  here's what seems to be a working fix.  It turns out that the existing, custom conversion code (nsWebSocket::ConvertTextToUTF8) doesn't insert replacement characters correctly (instead of replacing with '0xef 0xbf 0xbd', aka '\ufffd', it replaced with '0xed 0xa0 0x80'.  Which seems odd, because the code explicitly tells the converter to use UTF_8_REPLACEMENT_CHAR.   But I didn't spent too much time worrying about it, because it seems like we're fine just using CopyUTF16toUTF8(), which is what we're already using everywhere else in the logic.
Assignee: nobody → jduell.mcbugs
Attachment #638996 - Flags: review?(jonas)
Attachment #638996 - Flags: review?(jonas) → review+

Comment 3

5 years ago
Last Resolved: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla16
You need to log in before you can comment on or make changes to this bug.