Giter Site home page Giter Site logo

UTF-8 decoding is wrong about stomp-websocket HOT 2 OPEN

jmesnil avatar jmesnil commented on June 7, 2024
UTF-8 decoding is wrong

from stomp-websocket.

Comments (2)

Artiom-M avatar Artiom-M commented on June 7, 2024

My current workaround is to encode the message in JSON with ensure_ascii=True (I am using python for tests)

from stomp-websocket.

tobiassodergren avatar tobiassodergren commented on June 7, 2024

I have gotten the decoding part to work by including functionality from:
http://snipplr.com/view.php?codeview&id=31206

I introduced it in the compiled version of stomp.js, inside this.ws.onmessage. I don't have enough coffee-script skills to do an actual patch.

  this.ws.onmessage = (function(_this) {
    return function(evt) {
      var arr, c, client, data, frame, messageID, onreceive, subscription, unmarshalledData, _i, _len, _ref, _results;
      data = typeof ArrayBuffer !== 'undefined' && evt.data instanceof ArrayBuffer ? (arr = new Uint8Array(evt.data), typeof _this.debug === "function" ? _this.debug("--- got data length: " + arr.length) : void 0, ((function() {
        var _i, _len, _results;
        _results = [];
          for (_i = 0, _len = arr.length; _i < _len; _i++) {

              var byte1 = arr[_i];
              if( byte1 < 0x80 ) {
                  _results.push(String.fromCharCode(byte1));
              } else if( byte1 >= 0xC2 && byte1 < 0xE0 ) {
                  var byte2 = arr[++_i];
                  _results.push(String.fromCharCode(((byte1&0x1F)<<6) + (byte2&0x3F)));
              } else if( byte1 >= 0xE0 && byte1 < 0xF0 ) {
                  var byte2 = arr[++_i];
                  var byte3 = arr[++_i];
                  _results.push(String.fromCharCode(((byte1&0xFF)<<12) + ((byte2&0x3F)<<6) + (byte3&0x3F)));
              } else if( byte1 >= 0xF0 && byte1 < 0xF5) {
                  var byte2 = arr[++_i];
                  var byte3 = arr[++_i];
                  var byte4 = arr[++_i];
                  var codepoint = ((byte1&0x07)<<18) + ((byte2&0x3F)<<12)+ ((byte3&0x3F)<<6) + (byte4&0x3F);
                  codepoint -= 0x10000;
                  _results.push(String.fromCharCode(
                      (codepoint>>10) + 0xD800,
                      (codepoint&0x3FF) + 0xDC00
                  ));
              }
        }
        return _results;
      })()).join('')) : evt.data;

from stomp-websocket.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.