nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: node-nock/nock
Pull request #834 (2017-02-22 15:27:21)

fix for the "fix matchBody for multipart requests #425"
This fix contains a fix for multipart handling as already merged in #425. The tests had an error where `str1` aka `spec` was never run through `match_body.js`.


Patch:
diff --git a/lib/match_body.js b/lib/match_body.js
index be5215a..83784f0 100644
--- a/lib/match_body.js
+++ b/lib/match_body.js
@@ -29,7 +29,7 @@ function matchBody(spec, body) {
     return body.match(spec);
   }
 
-  if (typeof spec === "string") {
+  if (!isMultipart && typeof spec === "string") {
     spec = spec.replace(/\r?\n|\r/g, '');
   }
 


Test patch:
diff --git a/tests/test_body_match.js b/tests/test_body_match.js
index 25e5188..fb645cb 100644
--- a/tests/test_body_match.js
+++ b/tests/test_body_match.js
@@ -66,3 +66,22 @@ test('match body with empty object inside', function (t) {
     t.end();
   });
 })
+
+test('match body with form multipart', function(t) {
+
+  nock('http://encodingsareus.com')
+    .post('/', "--fixboundary\r\nContent-Disposition: form-data; name=\"field\"\r\n\r\nvalue\r\n--fixboundary--\r\n")
+    .reply(200);
+
+  var r = mikealRequest({
+    url: 'http://encodingsareus.com/',
+    method: 'post',
+  }, function(err, res) {
+    if (err) throw err;
+    assert.equal(res.statusCode, 200);
+    t.end();
+  });
+  var form = r.form();
+  form._boundary = 'fixboundary';  // fix boundary so that request could match at all
+  form.append('field', 'value');
+});
diff --git a/tests/test_common.js b/tests/test_common.js
index 822b0d1..a16295d 100644
--- a/tests/test_common.js
+++ b/tests/test_common.js
@@ -30,9 +30,7 @@ tap.test('matchBody should not ignore new line characters from strings when Cont
       'Content-Type': "multipart/form-data;"
     }
   }
-  var matched = matchBody.call(testThis, function (body) {
-    return body === str1;
-  }, str2);
+  var matched = matchBody.call(testThis, str1, str2);
   t.true(matched);
   t.end()
 });
@@ -45,9 +43,7 @@ tap.test('matchBody should not ignore new line characters from strings when Cont
       'Content-Type': ["multipart/form-data;"]
     }
   }
-  var matched = matchBody.call(testThis, function (body) {
-    return body === str1;
-  }, str2);
+  var matched = matchBody.call(testThis, str1, str2);
   t.true(matched);
   t.end()
 });
Repository: node-nock/nock
Pull request #979 (2017-09-24 09:44:58)

compare falsy header values & numbers correctly
The "mocking succeeds when mocked and specified request headers have falsy values" which I made for #966 was still failing when run with `{only: true}` :/ I really don’t trust the tests much right now

Anyway, this fixes it for good now, I hope

coveralls: 
[![Coverage Status](https://coveralls.io/builds/13406095/badge)](https://coveralls.io/builds/13406095)

Coverage remained the same at 92.686% when pulling **d7b86971c81212d928037faa2e4795269577ee16 on handle-falsy-header-values** into **66cd477dbc3c262b4f55d045f161f0de3a2a0b15 on master**.


Patch:
diff --git a/lib/common.js b/lib/common.js
index d302c34..1a43170 100644
--- a/lib/common.js
+++ b/lib/common.js
@@ -320,9 +320,9 @@ function percentEncode(str) {
 }
 
 function matchStringOrRegexp(target, pattern) {
-  var str = target && target.toString ? target.toString() : target;
+  var str = !_.isUndefined(target) && target.toString ? target.toString() : target;
 
-  return pattern instanceof RegExp  ? str.match(pattern) : str === pattern;
+  return pattern instanceof RegExp  ? str.match(pattern) : str === String(pattern);
 }
 
 // return [newKey, newValue]


Test patch:
diff --git a/tests/test_common.js b/tests/test_common.js
index a16295d..3ed47a1 100644
--- a/tests/test_common.js
+++ b/tests/test_common.js
@@ -146,10 +146,12 @@ tap.test('deleteHeadersField deletes fields with case-insensitive field names',
 
 });
 
-tap.test('matchStringOrRegexp', function (t) {
+tap.test('matchStringOrRegexp', {only: true}, function (t) {
   t.true(common.matchStringOrRegexp('to match', 'to match'), 'true if pattern is string and target matches');
   t.false(common.matchStringOrRegexp('to match', 'not to match'), 'false if pattern is string and target doesn\'t match');
 
+  t.true(common.matchStringOrRegexp(123, 123), 'true if pattern is number and target matches');
+
   t.ok(common.matchStringOrRegexp('to match', /match/), 'match if pattern is regex and target matches');
   t.false(common.matchStringOrRegexp('to match', /not/), 'false if pattern is regex and target doesn\'t match');
   t.end();
Repository: node-nock/nock
Pull request #1010 (2017-10-26 21:06:16)

Added support for regex with query params
Followup to https://github.com/node-nock/nock/pull/973

Failing test in commit 1

A combination of a regex that is reliant on query params + allow unmocked would fail. Fix is in commit 2 https://github.com/node-nock/nock/pull/1010/commits/424f0eda1790c98e3b1105988e633c27b9e40294

cmswalker: @gr2m sorry, should have caught this in my original PR but wasn't combining `allowUnmocked: true` with regex's that need query params until recently

let me know

Patch:
diff --git a/lib/interceptor.js b/lib/interceptor.js
index 400eb57..e670b74 100755
--- a/lib/interceptor.js
+++ b/lib/interceptor.js
@@ -339,7 +339,10 @@ Interceptor.prototype.matchIndependentOfBody = function matchIndependentOfBody(o
         , path = options.path
         , proto = options.proto;
 
-    path = path ? path.split('?')[0] : '';
+    // NOTE: Do not split off the query params as the regex could use them
+    if (!isRegex) {
+        path = path ? path.split('?')[0] : '';
+    }
 
     if (this.scope.transformPathFunction) {
         path = this.scope.transformPathFunction(path);


Test patch:
diff --git a/tests/test_intercept.js b/tests/test_intercept.js
index dd5291b..5ffafe2 100644
--- a/tests/test_intercept.js
+++ b/tests/test_intercept.js
@@ -5126,6 +5126,24 @@ test('match multiple paths to domain using regexp with allowUnmocked (#835)', fu
   });
 });
 
+test('match domain and path using regexp with query params and allow unmocked', function(t) {
+  nock.cleanAll();
+  var imgResponse = 'Matched Images Page';
+  var opts = { allowUnmocked: true };
+
+  var scope = nock(/google/, opts)
+    .get(/imghp\?hl=en/)
+    .reply(200, imgResponse);
+
+  mikealRequest.get('http://www.google.com/imghp?hl=en', function (err, res, body) {
+    scope.done();
+    t.type(err, 'null');
+    t.equal(res.statusCode, 200);
+    t.equal(body, imgResponse);
+    t.end();
+  });
+});
+
 test('multiple interceptors override headers from unrelated request', function (t) {
   nock.cleanAll();
Repository: node-nock/nock
Pull request #1016 (2017-11-06 03:22:40)

Intercept ClientRequest.flushHeaders()


Patch:
diff --git a/lib/request_overrider.js b/lib/request_overrider.js
index 5285054..797160d 100644
--- a/lib/request_overrider.js
+++ b/lib/request_overrider.js
@@ -159,6 +159,16 @@ function RequestOverrider(req, options, interceptors, remove, cb) {
     }
   };
 
+  req.flushHeaders = function() {
+    debug('req.flushHeaders');
+    if (!aborted && !ended) {
+      end(cb);
+    }
+    if (aborted) {
+      emitError(new Error('Request aborted'));
+    }
+  };
+
   req.abort = function() {
     if (aborted) {
       return;


Test patch:
diff --git a/tests/test_common.js b/tests/test_common.js
index c5b2662..98931ba 100644
--- a/tests/test_common.js
+++ b/tests/test_common.js
@@ -157,7 +157,7 @@ tap.test('deleteHeadersField deletes fields with case-insensitive field names',
 
 });
 
-tap.test('matchStringOrRegexp', {only: true}, function (t) {
+tap.test('matchStringOrRegexp', function (t) {
   t.true(common.matchStringOrRegexp('to match', 'to match'), 'true if pattern is string and target matches');
   t.false(common.matchStringOrRegexp('to match', 'not to match'), 'false if pattern is string and target doesn\'t match');
 
diff --git a/tests/test_intercept.js b/tests/test_intercept.js
index 5ffafe2..dbc8334 100644
--- a/tests/test_intercept.js
+++ b/tests/test_intercept.js
@@ -61,7 +61,7 @@ test("allow unmocked works (2)", function(t) {
   });
 });
 
-test("allow unmocked works after one interceptor is removed", {only: true}, function(t) {
+test("allow unmocked works after one interceptor is removed", function(t) {
   nock("https://example.org",{allowUnmocked: true}).
     get("/").
     reply(200, "Mocked");
@@ -72,9 +72,6 @@ test("allow unmocked works after one interceptor is removed", {only: true}, func
 
     mikealRequest("https://example.org/unmocked", function(err, resp, body) {
       t.error(err);
-      console.log(`\nbody ==============================`)
-      console.log(body)
-
       t.assert(~body.indexOf('Example Domain'));
       t.end();
     });
@@ -5235,6 +5232,25 @@ test('correctly parse request without specified path (#1003)', function(t) {
   }).end();
 });
 
+test('data is sent with flushHeaders', function(t) {
+  nock.cleanAll();
+
+  var scope1 = nock('https://example.com')
+    .get('')
+    .reply(200, 'this is data');
+
+  https.request({hostname: 'example.com'}, function(res) {
+    t.equal(res.statusCode, 200);
+    res.on('data', function(data) {
+      t.equal(data.toString(), 'this is data');
+    });
+    res.on('end', function() {
+      scope1.done();
+      t.end();
+    });
+  }).flushHeaders();
+});
+
 test("teardown", function(t) {
   var leaks = Object.keys(global)
     .splice(globalCount, Number.MAX_VALUE);
Repository: node-nock/nock
Pull request #1023 (2017-11-17 06:50:32)

fix regexp on nested json object
The querystring package does not stringify nested attributes of json object.
It'll broken regexp matching if request body contains complex json data.
```
> qs = require('querystring')
> qs.stringify({ a: { b: 1 } })
'a='
```

gr2m: Could you please add a test for the change to make sure we don’t break it again in future 🙏 
chenghung: @gr2m sure, one testcase has been added, please review it again, thanks.
gr2m: thanks a lot!

Patch:
diff --git a/lib/match_body.js b/lib/match_body.js
index e909fb6..eec18aa 100644
--- a/lib/match_body.js
+++ b/lib/match_body.js
@@ -1,7 +1,7 @@
 'use strict';
 
 var deepEqual = require('deep-equal');
-var qs = require('querystring');
+var qs = require('qs');
 
 module.exports =
 function matchBody(spec, body) {
diff --git a/package.json b/package.json
index f38248e..93b512e 100644
--- a/package.json
+++ b/package.json
@@ -174,7 +174,7 @@
     "lodash": "~4.17.2",
     "mkdirp": "^0.5.0",
     "propagate": "0.4.0",
-    "qs": "^6.0.2",
+    "qs": "^6.5.1",
     "semver": "^5.3.0"
   },
   "devDependencies": {


Test patch:
diff --git a/tests/test_body_match.js b/tests/test_body_match.js
index 96a1d60..b97b07b 100644
--- a/tests/test_body_match.js
+++ b/tests/test_body_match.js
@@ -88,6 +88,27 @@ test('match body with empty object inside', function (t) {
   });
 })
 
+test('match body with nested object inside', function (t) {
+
+  nock('http://encodingsareus.com')
+    .post('/', /x/)
+    .reply(200);
+
+  mikealRequest({
+    url: 'http://encodingsareus.com/',
+    method: 'post',
+    json: {
+      obj: {
+        x: 1
+      },
+    },
+  }, function(err, res) {
+    if (err) throw err;
+    assert.equal(res.statusCode, 200);
+    t.end();
+  });
+})
+
 test('doesn\'t match body with mismatching keys', function (t) {
   nock('http://encodingsareus.com')
     .post('/', { a: 'a' })
Repository: node-nock/nock
Pull request #1027 (2017-11-25 17:55:16)

Bug 976 expected https protocol
We must pass protocol [option](https://nodejs.org/dist/latest-v8.x/docs/api/http.html#http_http_request_options_callback) to the [ClientRequest constructor ](https://github.com/node-nock/nock/blob/master/lib/request_overrider.js#L258). By default, it uses `http:` [protocol](https://github.com/nodejs/node/blob/master/lib/_http_client.js#L112) but when we do https request our agent has `https:` protocol. If the protocol does not equal expected then the [error is thrown](https://github.com/nodejs/node/blob/master/lib/_http_client.js#L131)


Patch:
diff --git a/lib/request_overrider.js b/lib/request_overrider.js
index 797160d..e9f99d7 100644
--- a/lib/request_overrider.js
+++ b/lib/request_overrider.js
@@ -238,6 +238,9 @@ function RequestOverrider(req, options, interceptors, remove, cb) {
     /// like to change request.path in mid-flight.
     options.path = req.path;
 
+    // fixes #976
+    options.protocol = options.proto + ':';
+
     interceptors.forEach(function(interceptor) {
       //  For correct matching we need to have correct request headers - if these were specified.
       setRequestHeaders(req, options, interceptor);


Test patch:
diff --git a/tests/test_https_allowunmocked.js b/tests/test_https_allowunmocked.js
index a8b13e7..f37bb17 100644
--- a/tests/test_https_allowunmocked.js
+++ b/tests/test_https_allowunmocked.js
@@ -2,10 +2,11 @@
 
 var test          = require('tap').test;
 var mikealRequest = require('request');
+var nock          = require('../');
+
+nock.enableNetConnect();
 
 test('allowUnmocked for https', {skip: process.env.AIRPLANE}, function(t) {
-  var nock = require('../');
-  nock.enableNetConnect();
   nock('https://www.google.com/', {allowUnmocked: true})
   .get('/pathneverhit')
   .reply(200, {foo: 'bar'});
@@ -22,3 +23,23 @@ test('allowUnmocked for https', {skip: process.env.AIRPLANE}, function(t) {
     t.end();
   });
 });
+
+test('allowUnmocked for https with query test miss', {skip: process.env.AIRPLANE}, function(t) {
+  nock.cleanAll();
+  nock('https://www.google.com', {allowUnmocked: true})
+    .get('/search')
+    .query(function() {return false;})
+    .reply(500);
+
+  var options = {
+    method: 'GET',
+    uri: 'https://www.google.com/search'
+  };
+
+  mikealRequest(options, function(err, resp, body) {
+    t.notOk(err, 'should be no error');
+    t.true(typeof body !== 'undefined', 'body should not be undefined');
+    t.true(body.length !== 0, 'body should not be empty');
+    t.end();
+  });
+});
Repository: node-nock/nock
Pull request #1063 (2018-02-08 16:24:36)

Test for array like params in a application/x-www-form-urlencoded 
as discussed here https://github.com/node-nock/nock/issues/1051


Patch:
diff --git a/lib/match_body.js b/lib/match_body.js
index eec18aa..867a32e 100644
--- a/lib/match_body.js
+++ b/lib/match_body.js
@@ -27,7 +27,7 @@ function matchBody(spec, body) {
       body = json;
     } else {
       if (contentType && contentType.toString().match(/application\/x-www-form-urlencoded/)) {
-        body = qs.parse(body);
+        body = qs.parse(body, { allowDots: true });
       }
     }
   }


Test patch:
diff --git a/tests/test_body_match.js b/tests/test_body_match.js
index b97b07b..c2f454f 100644
--- a/tests/test_body_match.js
+++ b/tests/test_body_match.js
@@ -145,3 +145,32 @@ test('match body with form multipart', function(t) {
   form._boundary = 'fixboundary';  // fix boundary so that request could match at all
   form.append('field', 'value');
 });
+
+test('array like urlencoded form posts are correctly parsed', function(t) {
+
+  nock('http://encodingsareus.com')
+      .post('/',{
+        arrayLike: [
+          {
+            "fieldA": "0",
+            "fieldB": "data",
+            "fieldC": "value"
+          }
+        ]
+        })
+      .reply(200);
+
+  mikealRequest({
+    url: 'http://encodingsareus.com/',
+    method: 'post',
+    form: {
+      "arrayLike[0].fieldA": "0",
+      "arrayLike[0].fieldB": "data",
+      "arrayLike[0].fieldC": "value"
+    }
+  }, function(err, res) {
+    if (err) throw err;
+    assert.equal(res.statusCode, 200);
+    t.end();
+  });
+});
Repository: node-nock/nock
Pull request #1147 (2018-06-11 23:49:11)

fix(issue-1137): No match when basePath is regex and path is function
I had to update the port numbers in the `test_recorder.py` because the test cases were failing with the `EADDRINUSE` error for port 8081.


Patch:
diff --git a/lib/interceptor.js b/lib/interceptor.js
index 3e333b1..4009843 100644
--- a/lib/interceptor.js
+++ b/lib/interceptor.js
@@ -306,7 +306,7 @@ Interceptor.prototype.match = function match(options, body, hostNameOnly) {
 
     if (typeof this.uri === 'function') {
         matches = matchQueries &&
-            method.toUpperCase() + ' ' + proto + '://' + options.host === this.baseUri &&
+            common.matchStringOrRegexp(matchKey, this.basePath) &&
             this.uri.call(this, path);
     } else {
         matches = method === this.method &&
diff --git a/package.json b/package.json
index 9e800fe..86af0aa 100644
--- a/package.json
+++ b/package.json
@@ -191,7 +191,7 @@
     "nyc": "^12.0.1",
     "request": "^2.83.0",
     "request-promise": "^4.2.2",
-    "restify-clients": "^2.0.0",
+    "restify-clients": "^2.2.0",
     "rimraf": "^2.6.2",
     "semantic-release": "^15.0.0",
     "superagent": "^3.8.2",


Test patch:
diff --git a/tests/test_intercept.js b/tests/test_intercept.js
index c716dfc..3ff53e2 100644
--- a/tests/test_intercept.js
+++ b/tests/test_intercept.js
@@ -4569,7 +4569,22 @@ test('match domain using regexp', function (t) {
   });
 });
 
+test('match domain using regexp with path as callback (issue-1137)', function (t) {
+  nock.cleanAll();
+  nock(/.*/)
+    .get(() => true)
+    .reply(200, 'Match regex');
+
+  mikealRequest.get('http://www.regexexample.com/resources', function(err, res, body) {
+    t.type(err, 'null');
+    t.equal(res.statusCode, 200);
+    t.equal(body, 'Match regex');
+    t.end();
+  });
+});
+
 test('match multiple interceptors with regexp domain (issue-508)', function (t) {
+  nock.cleanAll();
   nock(/chainregex/)
     .get('/')
     .reply(200, 'Match regex')
diff --git a/tests/test_recorder.js b/tests/test_recorder.js
index 1160b0f..9ddfaa6 100644
--- a/tests/test_recorder.js
+++ b/tests/test_recorder.js
@@ -279,7 +279,7 @@ test('records nonstandard ports', function(t) {
   //  Create test http server and perform the tests while it's up.
   var testServer = http.createServer(function(req, res) {
     res.end(RESPONSE_BODY);
-  }).listen(8081, function(err) {
+  }).listen(8082, function(err) {
 
     t.equal(err, undefined);
 
@@ -741,7 +741,7 @@ test('works with clients listening for readable', {skip: process.env.AIRPLANE},
   //  Create test http server and perform the tests while it's up.
   var testServer = http.createServer(function(req, res) {
     res.end(RESPONSE_BODY);
-  }).listen(8081, function(err) {
+  }).listen(8082, function(err) {
 
     // t.equal(err, undefined);
 
@@ -882,7 +882,7 @@ test("respects http.request() consumers", function(t) {
     setTimeout(function() {
       res.end('bar');
     }, 25);
-  }).listen(8082, function(err) {
+  }).listen(8083, function(err) {
     t.equal(err, undefined);
 
     nock.restore();
Repository: node-fetch/node-fetch
Pull request #1445 (2022-01-08 07:48:41)

Create SECURITY.md
To let the repository confirm jimmy@warting.se as its security contact.


Patch:
diff --git a/SECURITY.md b/SECURITY.md
new file mode 100644
index 0000000..e60fc68
--- /dev/null
+++ b/SECURITY.md
@@ -0,0 +1,5 @@
+# Security Policy
+
+## Reporting a Vulnerability
+
+Please report security issues to `jimmy@warting.se`
\ No newline at end of file
diff --git a/src/body.js b/src/body.js
index 98196bc..b0fe16b 100644
--- a/src/body.js
+++ b/src/body.js
@@ -178,7 +178,10 @@ Object.defineProperties(Body.prototype, {
 	arrayBuffer: {enumerable: true},
 	blob: {enumerable: true},
 	json: {enumerable: true},
-	text: {enumerable: true}
+	text: {enumerable: true},
+	data: {get: deprecate(() => {},
+		'data doesn\'t exist, use json(), text(), arrayBuffer(), or body instead',
+		'https://github.com/node-fetch/node-fetch/issues/1000 (response)')}
 });
 
 /**
diff --git a/src/request.js b/src/request.js
index d13873b..76d7576 100644
--- a/src/request.js
+++ b/src/request.js
@@ -7,6 +7,7 @@
  */
 
 import {format as formatUrl} from 'node:url';
+import {deprecate} from 'node:util';
 import Headers from './headers.js';
 import Body, {clone, extractContentType, getTotalBytes} from './body.js';
 import {isAbortSignal} from './utils/is.js';
@@ -30,6 +31,10 @@ const isRequest = object => {
 	);
 };
 
+const doBadDataWarn = deprecate(() => {},
+	'.data is not a valid RequestInit property, use .body instead',
+	'https://github.com/node-fetch/node-fetch/issues/1000 (request)');
+
 /**
  * Request class
  *
@@ -58,6 +63,10 @@ export default class Request extends Body {
 		let method = init.method || input.method || 'GET';
 		method = method.toUpperCase();
 
+		if ('data' in init) {
+			doBadDataWarn();
+		}
+
 		// eslint-disable-next-line no-eq-null, eqeqeq
 		if ((init.body != null || (isRequest(input) && input.body !== null)) &&
 			(method === 'GET' || method === 'HEAD')) {


Test patch:
diff --git a/test/request.js b/test/request.js
index cb1956c..b8ba107 100644
--- a/test/request.js
+++ b/test/request.js
@@ -282,4 +282,16 @@ describe('Request', () => {
 			expect(result).to.equal('a=1');
 		});
 	});
+
+	it('should warn once when using .data (request)', () => new Promise(resolve => {
+		process.once('warning', evt => {
+			expect(evt.message).to.equal('.data is not a valid RequestInit property, use .body instead');
+			resolve();
+		});
+
+		// eslint-disable-next-line no-new
+		new Request(base, {
+			data: ''
+		});
+	}));
 });
diff --git a/test/response.js b/test/response.js
index b4721ea..34db312 100644
--- a/test/response.js
+++ b/test/response.js
@@ -241,4 +241,13 @@ describe('Response', () => {
 		expect(res.status).to.equal(0);
 		expect(res.statusText).to.equal('');
 	});
+
+	it('should warn once when using .data (response)', () => new Promise(resolve => {
+		process.once('warning', evt => {
+			expect(evt.message).to.equal('data doesn\'t exist, use json(), text(), arrayBuffer(), or body instead');
+			resolve();
+		});
+
+		new Response('a').data;
+	}));
 });