-
Notifications
You must be signed in to change notification settings - Fork 29.2k
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
assert: fix deepEqual always return true on URL #50853
base: main
Are you sure you want to change the base?
Conversation
e430f61
to
aab5308
Compare
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.
LGTM
Related test failure:
|
aab5308
to
42b8ba1
Compare
fixed |
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 detection is not checking for an actual instance of URL and it's just a heuristic which can trigger for lots of other objects as well. Assert has to be very strict about knowing what to check for. We would need a proper check for being an URL object and that's something we can not easily do.
Update: The check is actually just additive, so it should be ok in assert. I would still like to see if we can just rely upon changing URL instead of assert and util.
} else if (isURL(value) && !(recurseTimes > ctx.depth && ctx.depth !== null)) { | ||
base = value.href; | ||
if (keys.length === 0 && protoProps === undefined) { | ||
return base; |
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.
I think it would be valuable to see the object structure as before. With this change, it almost looks like a string without providing the information about being an URL object.
Overall, I am not fond of special handling URL during inspection, especially as our detection is only a heuristic that can definitely trigger for lots of other objects (Boolean(self?.href && self.protocol && self.auth === undefined && self.path === undefined)
). We could see if we want to change the implementation in URL itself that no special handling would be needed.
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.
@BridgeAR Hi.
I thought it would be a simple solution to using instanceof
, but I found that Using a symbol or instanceof would not be able to recognize URL objects coming from other implementations (e.g. in Electron)
in the annotation
Could you tell me in what direction you think the implementation of the URL object should be changed?
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.
That is the reason why we use the heuristic. Let's imagine a user handles websites and has a structure like: { href: 'string', protocol: 'ftp', country: 'GER' }
. It would now be detected as URL. Our detection is only working in URL itself, by expecting objects of a specific shape. It does not work for a general input case like inspect
. It is fine in assert, due to just parsing a few properties multiple times. The effective difference is triggering the getter for href.
I understand that it would be good to detect changes between input in case an assertion fails, I am just not sure how to ideally indicate that difference. We could consider activating custom inspection. It was turned off by default while using assertions as it is likely that it would show better debugging information in most cases. This just prevents getters from being accessed.
What is the status of this PR? Is there any way, can anyone help to move this forward? 😄 |
@meixg hi, What is the current status of this PR? |
This issue/PR was marked as stalled, it will be automatically closed in 30 days. If it should remain open, please leave a comment explaining why it should remain open. |
Hi! People appear to have been requesting updates since March. For that reason, I've marked this PR as |
} else if (isURL(value) && !(recurseTimes > ctx.depth && ctx.depth !== null)) { | ||
base = value.href; | ||
if (keys.length === 0 && protoProps === undefined) { | ||
return base; |
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.
That is the reason why we use the heuristic. Let's imagine a user handles websites and has a structure like: { href: 'string', protocol: 'ftp', country: 'GER' }
. It would now be detected as URL. Our detection is only working in URL itself, by expecting objects of a specific shape. It does not work for a general input case like inspect
. It is fine in assert, due to just parsing a few properties multiple times. The effective difference is triggering the getter for href.
I understand that it would be good to detect changes between input in case an assertion fails, I am just not sure how to ideally indicate that difference. We could consider activating custom inspection. It was turned off by default while using assertions as it is likely that it would show better debugging information in most cases. This just prevents getters from being accessed.
const a = new URL('http://foo'); | ||
const b = new URL('http://bar'); | ||
|
||
assertNotDeepOrStrict(a, b); |
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.
I wonder if we want a test for the error message, due to this being blocked for exactly that reason.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #50853 +/- ##
==========================================
+ Coverage 87.89% 88.41% +0.52%
==========================================
Files 652 652
Lines 186589 186604 +15
Branches 35750 36062 +312
==========================================
+ Hits 163999 164988 +989
+ Misses 15816 14889 -927
+ Partials 6774 6727 -47
|
Fixes: #50836