Skip to content

Commit

Permalink
fix: allowing dot notation parsing for x-www-form-urlencoded posts (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
stubar authored and gr2m committed Feb 21, 2018
1 parent ebeb815 commit df04e86
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/match_body.js
Expand Up @@ -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 });
}
}
}
Expand Down
29 changes: 29 additions & 0 deletions tests/test_body_match.js
Expand Up @@ -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();
});
});

0 comments on commit df04e86

Please sign in to comment.