From 49ce1885d995338509116908d0fddc3eb0c42d3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20So=CC=88dergren?= Date: Fri, 21 Nov 2014 09:31:06 +0100 Subject: [PATCH 1/4] Fix for decoding part of issue #74 --- lib/stomp-node.js | 2 +- lib/stomp.js | 32 +++++++++++++++++++++++++------- lib/stomp.min.js | 4 ++-- src/stomp.coffee | 32 ++++++++++++++++++++++++++------ 4 files changed, 54 insertions(+), 16 deletions(-) diff --git a/lib/stomp-node.js b/lib/stomp-node.js index 68660ee..a268274 100644 --- a/lib/stomp-node.js +++ b/lib/stomp-node.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.7.1 +// Generated by CoffeeScript 1.8.0 /* Stomp Over WebSocket http://www.jmesnil.net/stomp-websocket/doc/ | Apache License V2.0 diff --git a/lib/stomp.js b/lib/stomp.js index 9c30356..4c3a343 100644 --- a/lib/stomp.js +++ b/lib/stomp.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.7.1 +// Generated by CoffeeScript 1.8.0 /* Stomp Over WebSocket http://www.jmesnil.net/stomp-websocket/doc/ | Apache License V2.0 @@ -253,13 +253,31 @@ } 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; + var arr, byte1, byte2, byte3, byte4, charCode, client, codepoint, data, frame, i, 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, charCode = String.fromCharCode, i = 0, ((function() { + var _results; _results = []; - for (_i = 0, _len = arr.length; _i < _len; _i++) { - c = arr[_i]; - _results.push(String.fromCharCode(c)); + while (i < arr.length) { + byte1 = arr[i++]; + if (byte1 < 0x80) { + _results.push(charCode(byte1)); + } else if (byte1 >= 0xC2 && byte1 < 0xE0) { + byte2 = arr[i++]; + _results.push(charCode(((byte1 & 0x1F) << 6) + (byte2 & 0x3F))); + } else if (byte1 >= 0xE0 && byte1 < 0xF0) { + byte2 = arr[i++]; + byte3 = arr[i++]; + _results.push(charCode(((byte1 & 0xFF) << 12) + ((byte2 & 0x3F) << 6) + (byte3 & 0x3F))); + } else if (byte1 >= 0xF0 && byte1 < 0xF5) { + byte2 = arr[i++]; + byte3 = arr[i++]; + byte4 = arr[i++]; + codepoint = ((byte1 & 0x07) << 18) + ((byte2 & 0x3F) << 12) + ((byte3 & 0x3F) << 6) + (byte4 & 0x3F); + codepoint -= 0x10000; + _results.push(charCode((codepoint >> 10) + 0xD800, (codepoint & 0x3FF) + 0xDC00)); + } else { + _results.push(void 0); + } } return _results; })()).join('')) : evt.data; diff --git a/lib/stomp.min.js b/lib/stomp.min.js index dd0b1fa..260745c 100644 --- a/lib/stomp.min.js +++ b/lib/stomp.min.js @@ -1,8 +1,8 @@ -// Generated by CoffeeScript 1.7.1 +// Generated by CoffeeScript 1.8.0 /* Stomp Over WebSocket http://www.jmesnil.net/stomp-websocket/doc/ | Apache License V2.0 Copyright (C) 2010-2013 [Jeff Mesnil](http://jmesnil.net/) Copyright (C) 2012 [FuseSource, Inc.](http://fusesource.com) */ -(function(){var t,e,n,i,r={}.hasOwnProperty,o=[].slice;t={LF:"\n",NULL:"\x00"};n=function(){var e;function n(t,e,n){this.command=t;this.headers=e!=null?e:{};this.body=n!=null?n:""}n.prototype.toString=function(){var e,i,o,s,u;e=[this.command];o=this.headers["content-length"]===false?true:false;if(o){delete this.headers["content-length"]}u=this.headers;for(i in u){if(!r.call(u,i))continue;s=u[i];e.push(""+i+":"+s)}if(this.body&&!o){e.push("content-length:"+n.sizeOfUTF8(this.body))}e.push(t.LF+this.body);return e.join(t.LF)};n.sizeOfUTF8=function(t){if(t){return encodeURI(t).match(/%..|./g).length}else{return 0}};e=function(e){var i,r,o,s,u,a,c,f,h,l,p,d,g,b,m,v,y;s=e.search(RegExp(""+t.LF+t.LF));u=e.substring(0,s).split(t.LF);o=u.shift();a={};d=function(t){return t.replace(/^\s+|\s+$/g,"")};v=u.reverse();for(g=0,m=v.length;gy;c=p<=y?++b:--b){r=e.charAt(c);if(r===t.NULL){break}i+=r}}return new n(o,a,i)};n.unmarshall=function(n){var i,r,o,s;r=n.split(RegExp(""+t.NULL+t.LF+"*"));s={frames:[],partial:""};s.frames=function(){var t,n,o,s;o=r.slice(0,-1);s=[];for(t=0,n=o.length;t>> "+r)}while(true){if(r.length>this.maxWebSocketFrameSize){this.ws.send(r.substring(0,this.maxWebSocketFrameSize));r=r.substring(this.maxWebSocketFrameSize);if(typeof this.debug==="function"){this.debug("remaining = "+r.length)}}else{return this.ws.send(r)}}};r.prototype._setupHeartbeat=function(n){var r,o,s,u,a,c;if((a=n.version)!==i.VERSIONS.V1_1&&a!==i.VERSIONS.V1_2){return}c=function(){var t,e,i,r;i=n["heart-beat"].split(",");r=[];for(t=0,e=i.length;t>> PING"):void 0}}(this))}if(!(this.heartbeat.incoming===0||o===0)){s=Math.max(this.heartbeat.incoming,o);if(typeof this.debug==="function"){this.debug("check PONG every "+s+"ms")}return this.ponger=i.setInterval(s,function(t){return function(){var n;n=e()-t.serverActivity;if(n>s*2){if(typeof t.debug==="function"){t.debug("did not receive server activity for the last "+n+"ms")}return t.ws.close()}}}(this))}};r.prototype._parseConnect=function(){var t,e,n,i;t=1<=arguments.length?o.call(arguments,0):[];i={};switch(t.length){case 2:i=t[0],e=t[1];break;case 3:if(t[1]instanceof Function){i=t[0],e=t[1],n=t[2]}else{i.login=t[0],i.passcode=t[1],e=t[2]}break;case 4:i.login=t[0],i.passcode=t[1],e=t[2],n=t[3];break;default:i.login=t[0],i.passcode=t[1],e=t[2],n=t[3],i.host=t[4]}return[i,e,n]};r.prototype.connect=function(){var r,s,u,a;r=1<=arguments.length?o.call(arguments,0):[];a=this._parseConnect.apply(this,r);u=a[0],this.connectCallback=a[1],s=a[2];if(typeof this.debug==="function"){this.debug("Opening Web Socket...")}this.ws.onmessage=function(i){return function(r){var o,u,a,c,f,h,l,p,d,g,b,m,v;c=typeof ArrayBuffer!=="undefined"&&r.data instanceof ArrayBuffer?(o=new Uint8Array(r.data),typeof i.debug==="function"?i.debug("--- got data length: "+o.length):void 0,function(){var t,e,n;n=[];for(t=0,e=o.length;ty;c=p<=y?++b:--b){r=e.charAt(c);if(r===t.NULL){break}i+=r}}return new n(s,a,i)};n.unmarshall=function(n){var i,r,s,o;r=n.split(RegExp(""+t.NULL+t.LF+"*"));o={frames:[],partial:""};o.frames=function(){var t,n,s,o;s=r.slice(0,-1);o=[];for(t=0,n=s.length;t>> "+r)}while(true){if(r.length>this.maxWebSocketFrameSize){this.ws.send(r.substring(0,this.maxWebSocketFrameSize));r=r.substring(this.maxWebSocketFrameSize);if(typeof this.debug==="function"){this.debug("remaining = "+r.length)}}else{return this.ws.send(r)}}};s.prototype._setupHeartbeat=function(n){var i,s,o,u,a,c;if((a=n.version)!==r.VERSIONS.V1_1&&a!==r.VERSIONS.V1_2){return}c=function(){var t,e,i,r;i=n["heart-beat"].split(",");r=[];for(t=0,e=i.length;t>> PING"):void 0}}(this))}if(!(this.heartbeat.incoming===0||s===0)){o=Math.max(this.heartbeat.incoming,s);if(typeof this.debug==="function"){this.debug("check PONG every "+o+"ms")}return this.ponger=r.setInterval(o,function(t){return function(){var n;n=e()-t.serverActivity;if(n>o*2){if(typeof t.debug==="function"){t.debug("did not receive server activity for the last "+n+"ms")}return t.ws.close()}}}(this))}};s.prototype._parseConnect=function(){var t,e,n,i;t=1<=arguments.length?o.call(arguments,0):[];i={};switch(t.length){case 2:i=t[0],e=t[1];break;case 3:if(t[1]instanceof Function){i=t[0],e=t[1],n=t[2]}else{i.login=t[0],i.passcode=t[1],e=t[2]}break;case 4:i.login=t[0],i.passcode=t[1],e=t[2],n=t[3];break;default:i.login=t[0],i.passcode=t[1],e=t[2],n=t[3],i.host=t[4]}return[i,e,n]};s.prototype.connect=function(){var s,u,a,c;s=1<=arguments.length?o.call(arguments,0):[];c=this._parseConnect.apply(this,s);a=c[0],this.connectCallback=c[1],u=c[2];if(typeof this.debug==="function"){this.debug("Opening Web Socket...")}this.ws.onmessage=function(r){return function(s){var o,a,c,f,h,l,p,d,g,b,m,v,y,w,S,k,I,N;g=typeof ArrayBuffer!=="undefined"&&s.data instanceof ArrayBuffer?(o=new Uint8Array(s.data),typeof r.debug==="function"?r.debug("--- got data length: "+o.length):void 0,l=String.fromCharCode,function(){var t;t=[];while(i=194&&a<224){c=o[i++];t.push(l(((a&31)<<6)+(c&63)))}else if(a>=224&&a<240){c=o[i++];f=o[i++];t.push(l(((a&255)<<12)+((c&63)<<6)+(f&63)))}else if(a>=240&&a<245){c=o[i++];f=o[i++];h=o[i++];d=((a&7)<<18)+((c&63)<<12)+((f&63)<<6)+(h&63);d-=65536;t.push(l((d>>10)+55296,(d&1023)+56320))}else{t.push(void 0)}}return t}().join("")):s.data;r.serverActivity=e();if(g===t.LF){if(typeof r.debug==="function"){r.debug("<<< PONG")}return}if(typeof r.debug==="function"){r.debug("<<< "+g)}w=n.unmarshall(r.partialData+g);r.partialData=w.partial;I=w.frames;N=[];for(S=0,k=I.length;S window?.console?.log message - + # Utility method to get the current timestamp (Date.now is not defined in IE8) now= -> if Date.now then Date.now() else new Date().valueOf - + # Base method to transmit any stomp frame _transmit: (command, headers, body) -> out = Frame.marshall(command, headers, body) @@ -252,7 +252,27 @@ class Client arr = new Uint8Array(evt.data) @debug? "--- got data length: #{arr.length}" # Return a string formed by all the char codes stored in the Uint8array - (String.fromCharCode(c) for c in arr).join('') + charCode = String.fromCharCode + i = 0; + (while i < arr.length + byte1 = arr[i++]; + if byte1 < 0x80 + charCode(byte1) + else if byte1 >= 0xC2 and byte1 < 0xE0 + byte2 = arr[i++] + charCode(((byte1 & 0x1F)<<6) + (byte2 & 0x3F)) + else if byte1 >= 0xE0 and byte1 < 0xF0 + byte2 = arr[i++] + byte3 = arr[i++] + charCode(((byte1 & 0xFF)<<12) + ((byte2 & 0x3F)<<6) + (byte3 & 0x3F)) + else if byte1 >= 0xF0 and byte1 < 0xF5 + byte2 = arr[i++] + byte3 = arr[i++] + byte4 = arr[i++] + codepoint = ((byte1 & 0x07)<<18) + ((byte2 & 0x3F)<<12)+ ((byte3 & 0x3F)<<6) + (byte4 & 0x3F) + codepoint -= 0x10000 + charCode((codepoint >> 10) + 0xD800, (codepoint & 0x3FF) + 0xDC00) + ).join('') else # take the data directly from the WebSocket `data` field evt.data @@ -398,7 +418,7 @@ class Client abort: -> client.abort txid } - + # [COMMIT Frame](http://stomp.github.com/stomp-specification-1.1.html#COMMIT) # # * `transaction` is MANDATORY. @@ -413,7 +433,7 @@ class Client @_transmit "COMMIT", { transaction: transaction } - + # [ABORT Frame](http://stomp.github.com/stomp-specification-1.1.html#ABORT) # # * `transaction` is MANDATORY. @@ -428,7 +448,7 @@ class Client @_transmit "ABORT", { transaction: transaction } - + # [ACK Frame](http://stomp.github.com/stomp-specification-1.1.html#ACK) # # * `messageID` & `subscription` are MANDATORY. From d48fd2ced491fd210ee0e6f0a8dac1ced5e057b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20So=CC=88dergren?= Date: Fri, 21 Nov 2014 09:41:36 +0100 Subject: [PATCH 2/4] Removed trailing semicolons --- lib/stomp.min.js | 2 +- src/stomp.coffee | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/stomp.min.js b/lib/stomp.min.js index 260745c..45541c7 100644 --- a/lib/stomp.min.js +++ b/lib/stomp.min.js @@ -5,4 +5,4 @@ Copyright (C) 2010-2013 [Jeff Mesnil](http://jmesnil.net/) Copyright (C) 2012 [FuseSource, Inc.](http://fusesource.com) */ -(function(){var t,e,n,r,s={}.hasOwnProperty,o=[].slice;t={LF:"\n",NULL:"\x00"};n=function(){var e;function n(t,e,n){this.command=t;this.headers=e!=null?e:{};this.body=n!=null?n:""}n.prototype.toString=function(){var e,i,r,o,u;e=[this.command];r=this.headers["content-length"]===false?true:false;if(r){delete this.headers["content-length"]}u=this.headers;for(i in u){if(!s.call(u,i))continue;o=u[i];e.push(""+i+":"+o)}if(this.body&&!r){e.push("content-length:"+n.sizeOfUTF8(this.body))}e.push(t.LF+this.body);return e.join(t.LF)};n.sizeOfUTF8=function(t){if(t){return encodeURI(t).match(/%..|./g).length}else{return 0}};e=function(e){var i,r,s,o,u,a,c,f,h,l,p,d,g,b,m,v,y;o=e.search(RegExp(""+t.LF+t.LF));u=e.substring(0,o).split(t.LF);s=u.shift();a={};d=function(t){return t.replace(/^\s+|\s+$/g,"")};v=u.reverse();for(g=0,m=v.length;gy;c=p<=y?++b:--b){r=e.charAt(c);if(r===t.NULL){break}i+=r}}return new n(s,a,i)};n.unmarshall=function(n){var i,r,s,o;r=n.split(RegExp(""+t.NULL+t.LF+"*"));o={frames:[],partial:""};o.frames=function(){var t,n,s,o;s=r.slice(0,-1);o=[];for(t=0,n=s.length;t>> "+r)}while(true){if(r.length>this.maxWebSocketFrameSize){this.ws.send(r.substring(0,this.maxWebSocketFrameSize));r=r.substring(this.maxWebSocketFrameSize);if(typeof this.debug==="function"){this.debug("remaining = "+r.length)}}else{return this.ws.send(r)}}};s.prototype._setupHeartbeat=function(n){var i,s,o,u,a,c;if((a=n.version)!==r.VERSIONS.V1_1&&a!==r.VERSIONS.V1_2){return}c=function(){var t,e,i,r;i=n["heart-beat"].split(",");r=[];for(t=0,e=i.length;t>> PING"):void 0}}(this))}if(!(this.heartbeat.incoming===0||s===0)){o=Math.max(this.heartbeat.incoming,s);if(typeof this.debug==="function"){this.debug("check PONG every "+o+"ms")}return this.ponger=r.setInterval(o,function(t){return function(){var n;n=e()-t.serverActivity;if(n>o*2){if(typeof t.debug==="function"){t.debug("did not receive server activity for the last "+n+"ms")}return t.ws.close()}}}(this))}};s.prototype._parseConnect=function(){var t,e,n,i;t=1<=arguments.length?o.call(arguments,0):[];i={};switch(t.length){case 2:i=t[0],e=t[1];break;case 3:if(t[1]instanceof Function){i=t[0],e=t[1],n=t[2]}else{i.login=t[0],i.passcode=t[1],e=t[2]}break;case 4:i.login=t[0],i.passcode=t[1],e=t[2],n=t[3];break;default:i.login=t[0],i.passcode=t[1],e=t[2],n=t[3],i.host=t[4]}return[i,e,n]};s.prototype.connect=function(){var s,u,a,c;s=1<=arguments.length?o.call(arguments,0):[];c=this._parseConnect.apply(this,s);a=c[0],this.connectCallback=c[1],u=c[2];if(typeof this.debug==="function"){this.debug("Opening Web Socket...")}this.ws.onmessage=function(r){return function(s){var o,a,c,f,h,l,p,d,g,b,m,v,y,w,S,k,I,N;g=typeof ArrayBuffer!=="undefined"&&s.data instanceof ArrayBuffer?(o=new Uint8Array(s.data),typeof r.debug==="function"?r.debug("--- got data length: "+o.length):void 0,l=String.fromCharCode,function(){var t;t=[];while(i=194&&a<224){c=o[i++];t.push(l(((a&31)<<6)+(c&63)))}else if(a>=224&&a<240){c=o[i++];f=o[i++];t.push(l(((a&255)<<12)+((c&63)<<6)+(f&63)))}else if(a>=240&&a<245){c=o[i++];f=o[i++];h=o[i++];d=((a&7)<<18)+((c&63)<<12)+((f&63)<<6)+(h&63);d-=65536;t.push(l((d>>10)+55296,(d&1023)+56320))}else{t.push(void 0)}}return t}().join("")):s.data;r.serverActivity=e();if(g===t.LF){if(typeof r.debug==="function"){r.debug("<<< PONG")}return}if(typeof r.debug==="function"){r.debug("<<< "+g)}w=n.unmarshall(r.partialData+g);r.partialData=w.partial;I=w.frames;N=[];for(S=0,k=I.length;Sy;c=p<=y?++b:--b){r=e.charAt(c);if(r===t.NULL){break}i+=r}}return new n(s,a,i)};n.unmarshall=function(n){var i,r,s,o;r=n.split(RegExp(""+t.NULL+t.LF+"*"));o={frames:[],partial:""};o.frames=function(){var t,n,s,o;s=r.slice(0,-1);o=[];for(t=0,n=s.length;t>> "+r)}while(true){if(r.length>this.maxWebSocketFrameSize){this.ws.send(r.substring(0,this.maxWebSocketFrameSize));r=r.substring(this.maxWebSocketFrameSize);if(typeof this.debug==="function"){this.debug("remaining = "+r.length)}}else{return this.ws.send(r)}}};r.prototype._setupHeartbeat=function(n){var r,s,o,u,a,c;if((a=n.version)!==i.VERSIONS.V1_1&&a!==i.VERSIONS.V1_2){return}c=function(){var t,e,i,r;i=n["heart-beat"].split(",");r=[];for(t=0,e=i.length;t>> PING"):void 0}}(this))}if(!(this.heartbeat.incoming===0||s===0)){o=Math.max(this.heartbeat.incoming,s);if(typeof this.debug==="function"){this.debug("check PONG every "+o+"ms")}return this.ponger=i.setInterval(o,function(t){return function(){var n;n=e()-t.serverActivity;if(n>o*2){if(typeof t.debug==="function"){t.debug("did not receive server activity for the last "+n+"ms")}return t.ws.close()}}}(this))}};r.prototype._parseConnect=function(){var t,e,n,i;t=1<=arguments.length?s.call(arguments,0):[];i={};switch(t.length){case 2:i=t[0],e=t[1];break;case 3:if(t[1]instanceof Function){i=t[0],e=t[1],n=t[2]}else{i.login=t[0],i.passcode=t[1],e=t[2]}break;case 4:i.login=t[0],i.passcode=t[1],e=t[2],n=t[3];break;default:i.login=t[0],i.passcode=t[1],e=t[2],n=t[3],i.host=t[4]}return[i,e,n]};r.prototype.connect=function(){var r,o,u,a;r=1<=arguments.length?s.call(arguments,0):[];a=this._parseConnect.apply(this,r);u=a[0],this.connectCallback=a[1],o=a[2];if(typeof this.debug==="function"){this.debug("Opening Web Socket...")}this.ws.onmessage=function(i){return function(r){var s,u,a,c,f,h,l,p,d,g,b,m,v,y,w,S,k,I,N;d=typeof ArrayBuffer!=="undefined"&&r.data instanceof ArrayBuffer?(s=new Uint8Array(r.data),typeof i.debug==="function"?i.debug("--- got data length: "+s.length):void 0,h=String.fromCharCode,b=0,function(){var t;t=[];while(b=194&&u<224){a=s[b++];t.push(h(((u&31)<<6)+(a&63)))}else if(u>=224&&u<240){a=s[b++];c=s[b++];t.push(h(((u&255)<<12)+((a&63)<<6)+(c&63)))}else if(u>=240&&u<245){a=s[b++];c=s[b++];f=s[b++];p=((u&7)<<18)+((a&63)<<12)+((c&63)<<6)+(f&63);p-=65536;t.push(h((p>>10)+55296,(p&1023)+56320))}else{t.push(void 0)}}return t}().join("")):r.data;i.serverActivity=e();if(d===t.LF){if(typeof i.debug==="function"){i.debug("<<< PONG")}return}if(typeof i.debug==="function"){i.debug("<<< "+d)}w=n.unmarshall(i.partialData+d);i.partialData=w.partial;I=w.frames;N=[];for(S=0,k=I.length;S= 0xC2 and byte1 < 0xE0 From 26d5abf790de3fa014a43c95a69c8ba02f7aee58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20So=CC=88dergren?= Date: Fri, 21 Nov 2014 12:39:48 +0100 Subject: [PATCH 3/4] #74 Changed test to include unicode character --- browsertests/unit/message.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/browsertests/unit/message.js b/browsertests/unit/message.js index bcc8263..4546560 100644 --- a/browsertests/unit/message.js +++ b/browsertests/unit/message.js @@ -22,7 +22,7 @@ test("Send and receive a message", function() { test("Send and receive a message with a JSON body", function() { var client = Stomp.client(TEST.url); - var payload = {text: "hello", bool: true, value: Math.random()}; + var payload = {text: "h\u00E4llo", bool: true, value: Math.random()}; client.connect(TEST.login, TEST.password, function() { From 1ba081bbdb3c3d654b5bce730ee9d3af1a2643c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20So=CC=88dergren?= Date: Fri, 21 Nov 2014 13:13:24 +0100 Subject: [PATCH 4/4] Additional unicode characters decoded correctly in test --- browsertests/unit/message.js | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/browsertests/unit/message.js b/browsertests/unit/message.js index 4546560..4241d4d 100644 --- a/browsertests/unit/message.js +++ b/browsertests/unit/message.js @@ -22,7 +22,7 @@ test("Send and receive a message", function() { test("Send and receive a message with a JSON body", function() { var client = Stomp.client(TEST.url); - var payload = {text: "h\u00E4llo", bool: true, value: Math.random()}; + var payload = {text: "hello", bool: true, value: Math.random()}; client.connect(TEST.login, TEST.password, function() { @@ -39,4 +39,26 @@ test("Send and receive a message with a JSON body", function() { client.send(TEST.destination, {}, JSON.stringify(payload)); }); stop(TEST.timeout); +}); + +test("Send and receive a message with a UTF-8 JSON body", function() { + + var client = Stomp.client(TEST.url); + var payload = {text: "\u0050 \u00E4 \u0496 \u09a8 \u1C4F \uD7A3 \uD800\uDD28", bool: true, value: Math.random()}; + + client.connect(TEST.login, TEST.password, + function() { + client.subscribe(TEST.destination, function(message) + { + start(); + var res = JSON.parse(message.body); + equals(res.text, payload.text); + equals(res.bool, payload.bool); + equals(res.value, payload.value); + client.disconnect(); + }); + + client.send(TEST.destination, {}, JSON.stringify(payload)); + }); + stop(TEST.timeout); }); \ No newline at end of file