-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
[v18.17] Same URLs are different #48886
Comments
cc @nodejs/url |
Calling console.log lazy loads the query parameter and initializes the searchParams causing this indifference when using deepEqual. Unfortunately, I don’t have a solution to this problem without seriously impacting the performance. |
I tested with Node.js v20.5.0 and I have no problem. const url = new URL("http://foo.org");
console.log(Object.getOwnPropertySymbols(url));
url.searchParams;
console.log(Object.getOwnPropertySymbols(url));
@anonrig Will this problem happen on v20? Or will it only be on v18? |
We use private properties in Node 20 because it is a breaking change coming from using symbols as a private property. That’s why the output is different in Node 18. |
By the way, if you want to do a equality check between url instances, compare their href attributes. That would be the fastest and most direct way. |
Do you mean using a |
The root cause of this inequality causes from Available solutions:
|
Wouldn't another solution to have a const searchParams = Symbol('query');
class URL{
get searchParams() {
if (!isURL(this))
throw new ERR_INVALID_THIS('URL');
if (this[searchParams] == null) {
this[searchParams] = new URLSearchParams(this.search);
this[searchParams][context] = this;
}
return this[searchParams];
}
} we could have something like: const searchParams = new SafeWeakMap();
class URL{
get searchParams() {
if (!isURL(this))
throw new ERR_INVALID_THIS('URL');
const cachedValue = searchParams.get(this)
if (cachedValue != null) {
return cachedValue;
}
const value = new URLSearchParams(this.search);
value[context] = this;
searchParams.set(this, value);
return value;
}
} It'd still be lazy but wouldn't affect the deep equality. |
Might work. Can you open a pull request to |
PR-URL: #48897 Refs: #48891 Refs: #48886 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Moshe Atlow <[email protected]>
PR-URL: nodejs#48897 Refs: nodejs#48891 Refs: nodejs#48886 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Moshe Atlow <[email protected]>
PR-URL: nodejs#48897 Refs: nodejs#48891 Refs: nodejs#48886 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Moshe Atlow <[email protected]>
PR-URL: nodejs#48897 Refs: nodejs#48891 Refs: nodejs#48886 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Moshe Atlow <[email protected]>
PR-URL: nodejs#48897 Refs: nodejs#48891 Refs: nodejs#48886 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Moshe Atlow <[email protected]>
Fixing this should also fix Chai: chaijs/deep-eql#97 |
PR-URL: nodejs#48897 Refs: nodejs#48891 Refs: nodejs#48886 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Moshe Atlow <[email protected]>
PR-URL: nodejs#48897 Refs: nodejs#48891 Refs: nodejs#48886 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Moshe Atlow <[email protected]>
PR-URL: nodejs#48897 Refs: nodejs#48891 Refs: nodejs#48886 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Moshe Atlow <[email protected]>
PR-URL: #48897 Refs: #48891 Refs: #48886 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Moshe Atlow <[email protected]>
PR-URL: #48897 Backport-PR-URL: #48891 Refs: #48891 Refs: #48886 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Moshe Atlow <[email protected]>
…to fail using deep equals assertion on url objects
…to fail using deep equals assertion on url objects (#176)
The latest v18.18 fixes this issue. |
Version
v18.17.0
Platform
Linux regseblaptop 5.19.0-46-generic #47~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Jun 21 15:35:31 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
Subsystem
No response
What steps will reproduce the bug?
How often does it reproduce? Is there a required condition?
The error occurs since Node.js v18.17.0.
What is the expected behavior? Why is that the expected behavior?
What do you see instead?
Additional information
console.log()
.The text was updated successfully, but these errors were encountered: