socket.io-parser
Advanced tools
+25
-4
@@ -221,4 +221,8 @@ | ||
| function Decoder() { | ||
| function Decoder(opts) { | ||
| this.reconstructor = null; | ||
| opts = opts || {}; | ||
| this.opts = { | ||
| maxAttachments: opts.maxAttachments || 10, | ||
| }; | ||
| } | ||
@@ -246,3 +250,3 @@ | ||
| } | ||
| packet = decodeString(obj); | ||
| packet = decodeString(obj, this.opts.maxAttachments); | ||
| if (exports.BINARY_EVENT === packet.type || exports.BINARY_ACK === packet.type) { // binary packet's json | ||
@@ -277,2 +281,3 @@ this.reconstructor = new BinaryReconstructor(packet); | ||
| * @param {String} str | ||
| * @param {Number} maxAttachments - the maximum number of binary attachments | ||
| * @return {Object} packet | ||
@@ -282,3 +287,3 @@ * @api private | ||
| function decodeString(str) { | ||
| function decodeString(str, maxAttachments) { | ||
| var i = 0; | ||
@@ -302,3 +307,9 @@ // look up type | ||
| } | ||
| p.attachments = Number(buf); | ||
| var n = Number(buf); | ||
| if (!isInteger(n) || n < 0) { | ||
| throw new Error("Illegal attachments"); | ||
| } else if (n > maxAttachments) { | ||
| throw new Error("too many attachments"); | ||
| } | ||
| p.attachments = n; | ||
| } | ||
@@ -440,1 +451,11 @@ | ||
| } | ||
| var isInteger = | ||
| Number.isInteger || | ||
| function (value) { | ||
| return ( | ||
| typeof value === "number" && | ||
| isFinite(value) && | ||
| Math.floor(value) === value | ||
| ); | ||
| }; |
+2
-2
| { | ||
| "name": "socket.io-parser", | ||
| "version": "3.4.3", | ||
| "version": "3.4.4", | ||
| "description": "socket.io protocol parser", | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "https://github.com/socketio/socket.io-parser.git" | ||
| "url": "git+https://github.com/socketio/socket.io.git" | ||
| }, | ||
@@ -9,0 +9,0 @@ "files": [ |
18058
3.28%530
3.92%