[Node 18.17] Same URLs are different
regseb opened this issue · comments
Sébastien Règne commented
Describe the bug
With Node.js 18.17.0, spied URLs are different from supplied URLs.
Files
-
package.json
{ "name": "testcase", "version": "1.0.0", "type": "module", "dependencies": { "sinon": "15.2.0" } }
-
index.js
import assert from "node:assert/strict"; import sinon from "sinon"; globalThis.foo = (url) => {}; const spy = sinon.spy(globalThis, "foo"); const link = "https://baz.org/"; const result = foo(new URL(link)); console.log("===== FIRST =====") assert.deepEqual(spy.firstCall.args[0], new URL(link)); console.log("===== CONSOLE =====") console.log(spy.firstCall.args[0]); console.log("===== SECOND =====") assert.deepEqual(spy.firstCall.args[0], new URL(link));
To Reproduce
Steps to reproduce the behavior:
npm install
node --version
v18.17.0
node index.js
===== FIRST =====
===== CONSOLE =====
URL {
href: 'https://baz.org/',
origin: 'https://baz.org',
protocol: 'https:',
username: '',
password: '',
host: 'baz.org',
hostname: 'baz.org',
port: '',
pathname: '/',
search: '',
searchParams: URLSearchParams {},
hash: ''
}
===== SECOND =====
node:internal/process/esm_loader:97
internalBinding('errors').triggerUncaughtException(
^
AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal:
+ actual - expected ... Lines skipped
+ <ref *1> URL {
- URL {
[Symbol(context)]: URLContext {
hash_start: 4294967295,
...
search_start: 4294967295,
username_end: 8
+ },
+ [Symbol(query)]: URLSearchParams {
+ [Symbol(context)]: [Circular *1],
+ [Symbol(query)]: []
}
}
at file:///home/regseb/testcase/index.js:18:8
at ModuleJob.run (node:internal/modules/esm/module_job:194:25) {
generatedMessage: true,
code: 'ERR_ASSERTION',
actual: <ref *1> URL {
[Symbol(context)]: URLContext {
href: 'https://baz.org/',
protocol_end: 6,
username_end: 8,
host_start: 8,
host_end: 15,
pathname_start: 15,
search_start: 4294967295,
hash_start: 4294967295,
port: 4294967295,
scheme_type: 2
},
[Symbol(query)]: URLSearchParams {
[Symbol(query)]: [],
[Symbol(context)]: [Circular *1]
}
},
expected: URL {
[Symbol(context)]: URLContext {
href: 'https://baz.org/',
protocol_end: 6,
username_end: 8,
host_start: 8,
host_end: 15,
pathname_start: 15,
search_start: 4294967295,
hash_start: 4294967295,
port: 4294967295,
scheme_type: 2
}
},
operator: 'deepStrictEqual'
}
Node.js v18.17.0
- Use previous Node.js version:
npm install node@18.16.1
node_modules/.bin/node --version
v18.16.1
node_modules/.bin/node index.js
===== FIRST =====
===== CONSOLE =====
URL {
href: 'https://baz.org/',
origin: 'https://baz.org',
protocol: 'https:',
username: '',
password: '',
host: 'baz.org',
hostname: 'baz.org',
port: '',
pathname: '/',
search: '',
searchParams: URLSearchParams {},
hash: ''
}
===== SECOND =====
Expected behavior
I'm expecting assert to find no difference between the two URLs.
Context (please complete the following information):
- Library version: 15.2.0
- Environment:
- Ubuntu 22.04.2 LTS
- Node.js v18.17.0
Additional context
- Node.js v18.17.0 comes with the latest version of the URL parser, Ada.
- The difference is found only after
console.log()
.
Sébastien Règne commented
I have reproduced the problem without Sinon. The problem comes from nodejs/node#48886
import assert from "node:assert/strict";
const link = "https://baz.org/";
const url = new URL(link);
console.log("===== FIRST =====")
assert.deepEqual(url, new URL(link));
console.log("===== CONSOLE =====")
console.log(url);
console.log("===== SECOND =====")
assert.deepEqual(url, new URL(link));