-
Notifications
You must be signed in to change notification settings - Fork 3.3k
fix: hasBinary flakiness #16641
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: hasBinary flakiness #16641
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Random observation: this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think so. The full code is like below: function hasBinary(obj, known = []) {
if (!obj || typeof obj !== "object") {
return false;
}
if (known.includes(obj)) {
return false
}
known.push(obj)
if (Array.isArray(obj)) {
for (let i = 0, l = obj.length; i < l; i++) {
if (hasBinary(obj[i], known)) {
return true;
}
}
return false;
}
if (isBinary(obj)) {
return true;
}
if (obj.toJSON &&
typeof obj.toJSON === "function" &&
arguments.length === 1) {
return hasBinary(obj.toJSON(), known);
}
for (const key in obj) {
if (Object.prototype.hasOwnProperty.call(obj, key) && hasBinary(obj[key], known)) {
return true;
}
}
return false;
} When we pass There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry I probably was not very clear. I specifically meant the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry. Forget the old comment. I misunderstood your comment again. I believe this can be fixed by removing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. awesome! |
||
typeof obj.toJSON === "function" && | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cause of the problem was the incorrect recursive call of
hasBinary
inside check Array section. Withoutknown
argument being passed, when checking arrays that have circular references,hasBinary
always starts from fresh.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤦 x 10000000