Repository: node-nock/nock (js)

Issue:
match is not a function
```
/home/centos/data/pf9-qbert/server/test/gke/node_modules/nock/lib/match_body.js:46
    return body.match(spec);
                ^

TypeError: body.match is not a function
    at Object.matchBody (/home/centos/data/pf9-qbert/server/test/gke/node_modules/nock/lib/match_body.js:46:17)
    at Interceptor.match (/home/centos/data/pf9-qbert/server/test/gke/node_modules/nock/lib/interceptor.js:326:30)
    at /home/centos/data/pf9-qbert/server/test/gke/node_modules/nock/lib/request_overrider.js:237:26
    at baseFindIndex (/home/centos/data/pf9-qbert/server/test/gke/node_modules/nock/node_modules/lodash/lodash.js:823:11)
    at findIndex (/home/centos/data/pf9-qbert/server/test/gke/node_modules/nock/node_modules/lodash/lodash.js:7275:14)
    at Function.find (/home/centos/data/pf9-qbert/server/test/gke/node_modules/nock/node_modules/lodash/lodash.js:5098:21)
    at RequestOverrider.end (/home/centos/data/pf9-qbert/server/test/gke/node_modules/nock/lib/request_overrider.js:236:21)
    at OverriddenClientRequest.RequestOverrider.req.end (/home/centos/data/pf9-qbert/server/test/gke/node_modules/nock/lib/request_overrider.js:153:7)
    at Request.end (/home/centos/data/pf9-qbert/server/node_modules/request/request.js:1515:14)
    at end (/home/centos/data/pf9-qbert/server/node_modules/request/request.js:548:16)
    at Immediate._onImmediate (/home/centos/data/pf9-qbert/server/node_modules/request/request.js:575:7)
    at processImmediate [as _immediateCallback] (timers.js:396:17)
```

Pull request description:
Fix body.exec is not a function
Re-add support for matching body to query string regex

Fixes #1005 and #1004 

This was working before the recent change to body parser. 

From the docs:

```
The request body can be a string, a RegExp, a JSON object or a function.
var scope = nock('http://myapp.iriscouch.com')
                .post('/users', /email=.?@gmail.com/gi)
                .reply(201, {
                  ok: true,
                  id: '123ABC',
                  rev: '946B7D1C'
                });
```


Patch:
diff --git a/lib/match_body.js b/lib/match_body.js
index 71f92bb..e909fb6 100644
--- a/lib/match_body.js
+++ b/lib/match_body.js
@@ -43,7 +43,11 @@ function matchBody(spec, body) {
   }
 
   if (spec instanceof RegExp) {
-    return body.match(spec);
+    if (typeof body === "string") {
+      return body.match(spec);
+    } else {
+      return qs.stringify(body).match(spec);
+    }
   }
 
   if (!isMultipart && typeof spec === "string") {


Test patch:
diff --git a/tests/test_body_match.js b/tests/test_body_match.js
index 3476125..96a1d60 100644
--- a/tests/test_body_match.js
+++ b/tests/test_body_match.js
@@ -5,6 +5,27 @@ var test = require('tap').test;
 var mikealRequest = require('request');
 var assert = require('assert');
 
+test('match body is regex trying to match string', function (t) {
+
+  nock('http://encodingsareus.com')
+    .post('/', new RegExp("a.+"))
+    .reply(200);
+
+  mikealRequest({
+    url: 'http://encodingsareus.com/',
+    method: 'post',
+    json: {
+      auth: {
+        passwd: 'abc'
+      }
+    },
+  }, function(err, res) {
+    if (err) throw err;
+    assert.equal(res.statusCode, 200);
+    t.end();
+  });
+
+});
 test('match body with regex', function (t) {
 
   nock('http://encodingsareus.com')