Skip to content

Commit

Permalink
fix: correctly parse request without specified path (#1011)
Browse files Browse the repository at this point in the history
fixes #1003
  • Loading branch information
n30n0v authored and gr2m committed Oct 28, 2017
1 parent 269377e commit eac534b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/common.js
Expand Up @@ -198,9 +198,11 @@ function stringifyRequest(options, body) {

if (port) port = ':' + port;

var path = options.path ? options.path : '';

var log = {
method: method,
url: options.proto + '://' + options.hostname + port + options.path,
url: options.proto + '://' + options.hostname + port + path,
headers: options.headers
};

Expand Down
2 changes: 1 addition & 1 deletion lib/interceptor.js
Expand Up @@ -339,7 +339,7 @@ Interceptor.prototype.matchIndependentOfBody = function matchIndependentOfBody(o
, path = options.path
, proto = options.proto;

path = path.split('?')[0];
path = path ? path.split('?')[0] : '';

if (this.scope.transformPathFunction) {
path = this.scope.transformPathFunction(path);
Expand Down
17 changes: 17 additions & 0 deletions tests/test_intercept.js
Expand Up @@ -5200,6 +5200,23 @@ test('match when query is specified with allowUnmocked (#490)', function (t) {
});
});

test('correctly parse request without specified path (#1003)', function(t) {
nock.cleanAll();

var scope1 = nock('https://example.com')
.get('')
.reply(200);

https.request({hostname: 'example.com'}, function(res) {
t.equal(res.statusCode, 200);
res.on('data', function() {});
res.on('end', function() {
scope1.done();
t.end();
});
}).end();
});

test("teardown", function(t) {
var leaks = Object.keys(global)
.splice(globalCount, Number.MAX_VALUE);
Expand Down

0 comments on commit eac534b

Please sign in to comment.