web-socket-js icon indicating copy to clipboard operation
web-socket-js copied to clipboard

Cannot receive "\uffff" correctly in Firefox 5 or before

Open rauchg opened this issue 15 years ago • 7 comments

When I attempt to send a unicode character like \uffff, the encoding breaks.

rauchg avatar Jul 29 '10 18:07 rauchg

I haven't read the spec, but possibly it doesn't support multibyte characters. To encode a string to a bytestring in JavaScript, you need to do unescape(encodeURIComponent(data)). Likewise, to decode it, you need to do decodeURIComponent(escape(data)).

eligrey avatar Jul 29 '10 19:07 eligrey

http://code.google.com/p/websocket-sample/wiki/Tips ("not to use encodeURIComponent" section)

rauchg avatar Jul 30 '10 17:07 rauchg

I don't think you understand what my code does. It doesn't add any bloat to the string itself, it just turns it into a bytestring. I'm not only using encodeURIComponent, which is what that tip says not to do.

eligrey avatar Jul 30 '10 18:07 eligrey

I think the article says that "WebSocket supports UTF-8 characters, so you don't need any encoding". This is true for web-socket-js too. Problem here is that, web-socket-js internally use encodeURIComponent/decodeURIComponent to pass data from JS to Flash, but decodeURIComponent(encodeURIComponent("\uffff")) != "\uffff" in Firefox. This looks bug of Firefox to me. escape/unescape actually works correctly for "\uffff" but it looks escape/unescape has another issue: https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Functions#escape_and_unescape_Functions

gimite avatar Aug 03 '10 14:08 gimite

FIrefox decodes percent-encoded U+FFFE and U+FFFF to U+FFFD. Discussion bug is here: https://bugzilla.mozilla.org/show_bug.cgi?id=520095

Masahiro-Yamada avatar Jan 20 '11 14:01 Masahiro-Yamada

see

https://bugzilla.mozilla.org/show_bug.cgi?id=686312

which is fixed in FF9

oberstet avatar Nov 11 '11 22:11 oberstet

Thanks for the information. So far we still use Flash implementation for Firefox, and the issue is implementation of encodeURIComponent/decodeURIComponent, which I'm not sure is also fixed by the change. Anyway we will use MozWebSocket when available #87 , so it will be fixed once we do that.

gimite avatar Nov 12 '11 00:11 gimite