Skip to content
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

[Node 18.17] Same URLs are different #2527

Closed
regseb opened this issue Jul 22, 2023 · 1 comment
Closed

[Node 18.17] Same URLs are different #2527

regseb opened this issue Jul 22, 2023 · 1 comment

Comments

@regseb
Copy link

regseb commented Jul 22, 2023

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:

  1. npm install
  2. node --version
v18.17.0
  1. 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
  1. Use previous Node.js version: npm install [email protected]
  2. node_modules/.bin/node --version
v18.16.1
  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

@regseb
Copy link
Author

regseb commented Jul 22, 2023

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));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant