Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions packages/socket/patches/socket.io-parser+4.0.4.patch
Original file line number Diff line number Diff line change
Expand Up @@ -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..e444014 100644
index 4b7c234..f588141 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 @@
Expand All @@ -126,10 +126,11 @@ index 4b7c234..e444014 100644
const withNativeArrayBuffer = typeof ArrayBuffer === "function";
const isView = (obj) => {
return typeof ArrayBuffer.isView === "function"
@@ -15,23 +16,37 @@ const withNativeFile = typeof File === "function" ||
@@ -14,24 +15,38 @@ const withNativeBlob = typeof Blob === "function" ||
const withNativeFile = typeof File === "function" ||
(typeof File !== "undefined" &&
toString.call(File) === "[object FileConstructor]");
/**
+/**
+ * Returns true if obj is an ArrayBuffer.
+ * This extra check is made because the "instanceof ArrayBuffer" check does not work
+ * across different execution contexts.
Expand All @@ -138,7 +139,7 @@ index 4b7c234..e444014 100644
+function isArrayBuffer(obj) {
+ return typeof obj === 'object' && obj !== null && toString.call(obj) === '[object ArrayBuffer]';
+}
+/**
/**
* Returns true if obj is a Buffer, an ArrayBuffer, a Blob or a File.
*
* @private
Expand All @@ -153,7 +154,7 @@ index 4b7c234..e444014 100644
}
exports.isBinary = isBinary;
-function hasBinary(obj, toJSON) {
+function hasBinary(obj, known = []) {
+function hasBinary(obj, known = [], toJSON = false) {
if (!obj || typeof obj !== "object") {
return false;
}
Expand All @@ -168,12 +169,14 @@ index 4b7c234..e444014 100644
return true;
}
}
@@ -43,10 +58,10 @@ function hasBinary(obj, toJSON) {
@@ -42,11 +57,11 @@ function hasBinary(obj, toJSON) {
}
if (obj.toJSON &&
typeof obj.toJSON === "function" &&
arguments.length === 1) {
- arguments.length === 1) {
- return hasBinary(obj.toJSON(), true);
+ return hasBinary(obj.toJSON(), known);
+ arguments.length === 2) {
+ return hasBinary(obj.toJSON(), known, true);
}
for (const key in obj) {
- if (Object.prototype.hasOwnProperty.call(obj, key) && hasBinary(obj[key])) {
Expand Down
15 changes: 15 additions & 0 deletions packages/socket/test/socket_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const path = require('path')
const server = require('socket.io')
const client = require('socket.io-client')
const parser = require('socket.io-parser')
const { hasBinary } = require('socket.io-parser/dist/is-binary')
const expect = require('chai').expect
const pkg = require('../package.json')
const lib = require('../index')
Expand Down Expand Up @@ -217,4 +218,18 @@ describe('Socket', function () {
}
})
})

context('hasBinary', () => {
it('hasBinary handles binary data in toJSON()', () => {
const x = {
toJSON () {
return Buffer.from('123', 'utf8')
},
}

const data = ['a', x]

expect(hasBinary(data)).to.be.true
})
})
})