Skip to content

[fix] agent.query() is shadowed by HTTP method handler and therefore fails with "TypeError: Invalid URL" #860

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

Open
3 tasks done
sergburn opened this issue May 19, 2025 · 0 comments
Labels

Comments

@sergburn
Copy link

sergburn commented May 19, 2025

Describe the bug

Node.js version: 20.19.2

OS version: Mac OS 15.4.1

Description: An attempt to call supertest.agent.query(<object>) fails with "TypeError: Invalid URL". This does not happen in Node v20.19.1, but does so in 20.19.2, apparently because of llhttp upgrade. The "query" is another HTTP method and methods.forEach() in agent.js overwrites the query() function in superagent. (However, it looks like the same mistake is made in superagent as well)

Verified that same happens in Node 22.15.1

Actual behavior

The call fails with TypeError.

node:internal/url:818
      href = bindingUrl.parse(input, base, true);
                        ^

TypeError: Invalid URL
    at new URL (node:internal/url:818:25)
    at TestAgent._attachCookies (.../node_modules/superagent/lib/node/agent.js:69:17)
    at TestAgent.<computed> [as query] (.../node_modules/supertest/lib/agent.js:77:10

Expected behavior

This call is expected to store query parameters map in Agent's "defaults" to be re-used with following post()/get()/put() etc calls.

Code to reproduce

const supertest = require('supertest');
const agent = supertest.agent('http://localhost:3000');
agent.query({ param: 'test' });

Checklist

  • I have searched through GitHub issues for similar issues.
  • I have completely read through the README and documentation.
  • I have tested my code with the latest version of Node.js and this package and confirmed it is still not working.
@sergburn sergburn added the bug label May 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant