Skip to content

Commit

Permalink
fix: Fix crash when matching certain objects (#1714)
Browse files Browse the repository at this point in the history
When matching objects with the same number of keys but different keys, should not match instead of crashing.

Close #1713
  • Loading branch information
paulmelnikow committed Sep 12, 2019
1 parent d7b2c92 commit fa0a08a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/common.js
Expand Up @@ -578,6 +578,10 @@ function deepEqual(expected, actual) {
}

if (Array.isArray(expected) || _.isPlainObject(expected)) {
if (actual === undefined) {
return false
}

const expKeys = Object.keys(expected)
if (expKeys.length !== Object.keys(actual).length) {
return false
Expand Down
19 changes: 19 additions & 0 deletions tests/test_body_match.js
Expand Up @@ -214,6 +214,25 @@ test("doesn't match body with mismatching keys", t => {
)
})

// https://github.com/nock/nock/issues/1713
test("doesn't match body with same number of keys but different keys", t => {
nock('http://example.test')
.post('/', { a: {} })
.reply()

mikealRequest(
{
url: 'http://example.test',
method: 'post',
json: { b: 123 },
},
function(err) {
assert.ok(err)
t.end()
}
)
})

test('match body with form multipart', t => {
nock('http://example.test')
.post(
Expand Down

0 comments on commit fa0a08a

Please sign in to comment.