Skip to content

Commit

Permalink
fix: support for regex with query params (#1010)
Browse files Browse the repository at this point in the history
  • Loading branch information
cmswalker authored and gr2m committed Oct 28, 2017
1 parent eac534b commit a908ed9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/interceptor.js
Expand Up @@ -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);
Expand Down
18 changes: 18 additions & 0 deletions tests/test_intercept.js
Expand Up @@ -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();

Expand Down

0 comments on commit a908ed9

Please sign in to comment.