node-modules / urllib

Request HTTP(s) URLs in a complex world.
MIT License
725 stars 115 forks source link

fix: Don't mutate passed URL object #470

Closed tremby closed 11 months ago

tremby commented 11 months ago

Before this change, a passed URL object would be mutated if query parameters were appended via the data option.

Now we clone the object instead, so the original is not affected.


Background:

I am passing URL objects to the request method, and then adding query parameters via the data option. Example:

import { request } from "urllib";

const url = new URL("http://example.com");

await request(url, { data: { param1: "value1" } });

I found that if I then make another request to the same URL but with different parameters:

await request(url, { data: { param2: "value2" } });

...a request is actually made to http://example.com?param1=value1&param2=value2.

My URL object is being mutated by the urllib library. I see this as a bug.

codecov[bot] commented 11 months ago

Codecov Report

Merging #470 (5f043e8) into master (8c4ec6c) will increase coverage by 0.00%. Report is 4 commits behind head on master. The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master     #470   +/-   ##
=======================================
  Coverage   99.64%   99.64%           
=======================================
  Files           8        9    +1     
  Lines        1411     1423   +12     
  Branches      253      253           
=======================================
+ Hits         1406     1418   +12     
  Misses          5        5           
Files Changed Coverage Δ
src/HttpClient.ts 99.57% <100.00%> (+<0.01%) :arrow_up:

... and 3 files with indirect coverage changes

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more

fengmk2 commented 11 months ago

@tremby Thanks for your patient contribution!