Giter VIP home page Giter VIP logo

Comments (4)

domeq avatar domeq commented on July 29, 2024 1

This seems to be my problem as well.

Starting from release 13.3.5 (getting rid of lodash) my integration tests started failing.
After some debugging it seems the culprit is the expand function which started to behave differently than before for URLs containing querystring params that are named like object properties e.g. https://www.example.com?q=foo&q.something=bar.

The following code works fine on 13.3.4, but fails on 13.3.5:

const nock = require('nock');
const fetch = require('node-fetch');

nock('https://www.example.com').get('/').query({ q: 'foo', 'q.something': 'bar' }).reply(200, 'hey');

fetch('https://www.example.com?q=foo&q.something=bar')
    .then((res) => res.text())
    .then((text) => console.log(text, 'text'));

It's the same story with parameters like q.something and q[something] - both used to work just fine until the 13.3.5 release.

from nock.

bartoszhernas avatar bartoszhernas commented on July 29, 2024

The fix as a patch for pnpm:

diff --git a/lib/common.js b/lib/common.js
index 97d7c30e4602157b2bf1d475afa6b79525fda606..82ed39892109e51375acf86fa18ca8028796d78d 100644
--- a/lib/common.js
+++ b/lib/common.js
@@ -499,7 +499,7 @@ function isStream(obj) {
 function normalizeClientRequestArgs(input, options, cb) {
   if (typeof input === 'string') {
     input = urlToOptions(new url.URL(input))
-  } else if (input instanceof url.URL) {
+  } else if (input instanceof url.URL || input.constructor.name === 'URL') {
     input = urlToOptions(input)
   } else {
     cb = options
@@ -731,7 +731,7 @@ const expand = input => {
             resultPtr[part] = {}
           }
         }
-        resultPtr = resultPtr[part]
+        resultPtr = { __nock_value: resultPtr[part] }
       }
     }
   }

The first part is a fix for something else (Clickhouse Node JS library doesn't work with nock without this fix as it's uses URLImpl class for URLs. Checking constructor name worked better in this case).

The second part is fix to always make sure the value is an object.

from nock.

mikicho avatar mikicho commented on July 29, 2024

Thanks @bartoszhernas!
Would you mind creating a pull request and adding a test?

from nock.

bartoszhernas avatar bartoszhernas commented on July 29, 2024

Two bug fixes with two corresponding tests added to PR.

I realised while writing test, that my original fix was really bad and was hiding the issue and braking URL comparison 🥶

from nock.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.