kopia lustrzana https://github.com/c9/core
Revert "Escape only invalid character sequences in reliable socket"
rodzic
44396417e6
commit
2aac81b7e7
|
@ -7,7 +7,7 @@ module.exports = function(options, imports, register) {
|
||||||
imports["connect.render"].registerEngine("ejs", createView);
|
imports["connect.render"].registerEngine("ejs", createView);
|
||||||
|
|
||||||
ejs.filters.JSONToJS = function(obj, indent) {
|
ejs.filters.JSONToJS = function(obj, indent) {
|
||||||
return JSON.stringify(obj, null, indent).replace(/<\/?script|[\u2028\u2029\ud800-\uDFFF\ufeff]/ig, function(a) {
|
return JSON.stringify(obj, null, indent).replace(/<\/?script|[\u2028\u2029]/ig, function(a) {
|
||||||
var h = a.charCodeAt(0).toString(16);
|
var h = a.charCodeAt(0).toString(16);
|
||||||
return (h.length == 2 ? "\\x" : "\\u") + h + a.substr(1);
|
return (h.length == 2 ? "\\x" : "\\u") + h + a.substr(1);
|
||||||
});
|
});
|
||||||
|
|
|
@ -64,22 +64,10 @@ Object.defineProperty(ReliableSocket.prototype, "readyState", {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function utf8escape(str) {
|
|
||||||
return str.replace(/[\ud799-\uDFFF]/g, function(x) {
|
|
||||||
return "\ud799" + String.fromCharCode(x.charCodeAt(0) - 0xd700);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function utf8unescape(str) {
|
|
||||||
return str.replace(/\ud799./g, function(x) {
|
|
||||||
return String.fromCharCode(x.charCodeAt(1) + 0xd700);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
ReliableSocket.prototype.onMessage = function(msg) {
|
ReliableSocket.prototype.onMessage = function(msg) {
|
||||||
if (typeof msg == "string") {
|
if (typeof msg == "string") {
|
||||||
try {
|
try {
|
||||||
msg = JSON.parse(utf8unescape(msg));
|
msg = JSON.parse(unescape(msg));
|
||||||
} catch(e) {}
|
} catch(e) {}
|
||||||
}
|
}
|
||||||
this.debug && console.log("on message", msg, this.seq);
|
this.debug && console.log("on message", msg, this.seq);
|
||||||
|
@ -240,7 +228,7 @@ ReliableSocket.prototype._cancelDelayedAck = function() {
|
||||||
ReliableSocket.prototype._ack = function() {
|
ReliableSocket.prototype._ack = function() {
|
||||||
if (this.socket.readyState == "open") {
|
if (this.socket.readyState == "open") {
|
||||||
this.debug && console.log("send ack", this.recId);
|
this.debug && console.log("send ack", this.recId);
|
||||||
this.socket.send(utf8escape(JSON.stringify({
|
this.socket.send(encodeURI(JSON.stringify({
|
||||||
ack: this.recId
|
ack: this.recId
|
||||||
})));
|
})));
|
||||||
}
|
}
|
||||||
|
@ -336,7 +324,7 @@ ReliableSocket.prototype._sendMessage = function(data, type) {
|
||||||
that._updateRetransmissionTimeout(Date.now() - msg.ts);
|
that._updateRetransmissionTimeout(Date.now() - msg.ts);
|
||||||
},
|
},
|
||||||
serialize: function() {
|
serialize: function() {
|
||||||
return utf8escape(JSON.stringify({
|
return escape(JSON.stringify({
|
||||||
ack: that.recId,
|
ack: that.recId,
|
||||||
seq: msg.seq,
|
seq: msg.seq,
|
||||||
d: data,
|
d: data,
|
||||||
|
|
|
@ -2,6 +2,6 @@ define(function(require, exports, module) {
|
||||||
|
|
||||||
// on each backwards incompatible protocol change the version number must be
|
// on each backwards incompatible protocol change the version number must be
|
||||||
// increased
|
// increased
|
||||||
exports.protocol = 10;
|
exports.protocol = 9;
|
||||||
|
|
||||||
});
|
});
|
Ładowanie…
Reference in New Issue