diff --git a/packages/socket/patches/socket.io-parser+4.0.4.patch b/packages/socket/patches/socket.io-parser+4.0.4.patch index 5089fa3f14..7eed9769e7 100644 --- a/packages/socket/patches/socket.io-parser+4.0.4.patch +++ b/packages/socket/patches/socket.io-parser+4.0.4.patch @@ -115,7 +115,7 @@ index 0ef9f80..4cd787e 100644 catch (e) { return false; diff --git a/node_modules/socket.io-parser/dist/is-binary.js b/node_modules/socket.io-parser/dist/is-binary.js -index 4b7c234..95469f7 100644 +index 4b7c234..15ed5b1 100644 --- a/node_modules/socket.io-parser/dist/is-binary.js +++ b/node_modules/socket.io-parser/dist/is-binary.js @@ -1,6 +1,7 @@ @@ -126,7 +126,7 @@ index 4b7c234..95469f7 100644 const withNativeArrayBuffer = typeof ArrayBuffer === "function"; const isView = (obj) => { return typeof ArrayBuffer.isView === "function" -@@ -22,13 +23,18 @@ const withNativeFile = typeof File === "function" || +@@ -22,16 +23,21 @@ const withNativeFile = typeof File === "function" || function isBinary(obj) { return ((withNativeArrayBuffer && (obj instanceof ArrayBuffer || isView(obj))) || (withNativeBlob && obj instanceof Blob) || @@ -146,7 +146,11 @@ index 4b7c234..95469f7 100644 + known.push(obj) if (Array.isArray(obj)) { for (let i = 0, l = obj.length; i < l; i++) { - if (hasBinary(obj[i])) { +- if (hasBinary(obj[i])) { ++ if (hasBinary(obj[i], known)) { + return true; + } + } @@ -43,10 +49,10 @@ function hasBinary(obj, toJSON) { if (obj.toJSON && typeof obj.toJSON === "function" && diff --git a/packages/socket/test/socket_spec.js b/packages/socket/test/socket_spec.js index d903d51775..09383c713b 100644 --- a/packages/socket/test/socket_spec.js +++ b/packages/socket/test/socket_spec.js @@ -114,6 +114,41 @@ describe('Socket', function () { } }) + it('correctly encodes and decodes circular data in array', (done) => { + const encoder = new parser.Encoder() + + const circularObj = { + foo: {}, + } + + circularObj.foo.circularArray = [circularObj, circularObj] + + const obj = { + type: PacketType.EVENT, + data: ['a', circularObj], + id: 23, + nsp: '/cool', + } + + const originalData = obj.data + + const encodedPackets = encoder.encode(obj) + + const decoder = new parser.Decoder() + + decoder.on('decoded', (packet) => { + obj.data = originalData + expect(packet.data[1] === packet.data[1].foo.circularArray[0]).to.be.true + expect(packet.data[1] === packet.data[1].foo.circularArray[1]).to.be.true + expect(packet).to.eql(obj) + done() + }) + + for (let i = 0; i < encodedPackets.length; i++) { + decoder.add(encodedPackets[i]) + } + }) + it('correctly encodes and decodes circular data containing binary', (done) => { const encoder = new parser.Encoder()