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

URL search parameter mangled / modified by GOT #1202

Closed
cookch10 opened this issue Apr 27, 2020 · 1 comment
Closed

URL search parameter mangled / modified by GOT #1202

cookch10 opened this issue Apr 27, 2020 · 1 comment

Comments

@cookch10
Copy link

cookch10 commented Apr 27, 2020

Describe the bug

  • Node.js version: 12.13.1
  • OS & version: Windows 10 x64

When passing in a URL object (or string) to got, the path changes from what was originally passed in.

Actual behavior

Given the following url:

const uri = new URL('https://www.external.com/path/morepath?someparam&&param=value&param2=value2&param3=value3&param4=value4&param5=value5&param6=');

gotInstance.stream(uri, {
})
  .on('error', (error) => {
    next();
  })
  .on('request', (req) => {
    // At this point, req.path now equals '/path/morepath?someparam=&param=value&param2=value2&param3=value3&param4=value4&param5=value5&param6='
  })
  .pipe(res);

The initial URL path is: /path/morepath?someparam&&param=value&param2=value2&param3=value3&param4=value4&param5=value5&param6=

After passing through got, the path becomes: /path/morepath?someparam=&param=value&param2=value2&param3=value3&param4=value4&param5=value5&param6=
...

Expected behavior

got should not be modifying the url I am passing in, as it causes the requested resource to respond with an error. The endpoint (which I have no control over) is expecting the original url path and query string.
...

Code to reproduce

see above

I've created the following (hack) workaround by doing the following:

const uri = new URL('https://www.external.com/path/morepath?someparam&&param=value&param2=value2&param3=value3&param4=value4&param5=value5&param6=');

const _search = uri.search;

Object.defineProperty(uri, 'search', {
  get() {
    return _search;
  },
  set() {
  }
});

As far as I can tell, this is happening due to the following code in source/core/index.ts:

const triggerSearchParameters = '_GOT_INTERNAL_TRIGGER_NORMALIZATION';

Checklist

  • [X ] I have read the documentation.
  • [ X] I have tried my code with the latest version of Node.js and Got.
@szmarczak
Copy link
Collaborator

The behavior is correct. See nodejs/node#33037

Got just triggers the normalization manually due to the bug mentioned above.

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

2 participants