Skip to content

Commit

Permalink
fix: updated isSimpleObject util to only check plain objects not arra…
Browse files Browse the repository at this point in the history
…ys (#1865)
  • Loading branch information
bizob2828 committed Nov 14, 2023
1 parent a7786f3 commit 8baa5bc
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/instrumentation/@elastic/elasticsearch.js
Expand Up @@ -67,7 +67,7 @@ function queryParser(params) {
// let body or bulkBody override querystring, as some requests have both
if (isNotEmpty(params.body)) {
queryParam = params.body
} else if (isNotEmpty(params.bulkBody)) {
} else if (Array.isArray(params.bulkBody) && params.bulkBody.length) {
queryParam = params.bulkBody
}

Expand Down
2 changes: 1 addition & 1 deletion lib/util/objects.js
Expand Up @@ -13,7 +13,7 @@ exports = module.exports = { isSimpleObject, isNotEmpty }
* @returns {boolean} whether or not the value is an object and not null
*/
function isSimpleObject(thing) {
return 'object' === typeof thing && thing !== null
return Object.prototype.toString.call(thing) === '[object Object]' && thing !== null
}

/**
Expand Down
5 changes: 3 additions & 2 deletions test/unit/util/objects.test.js
Expand Up @@ -10,10 +10,11 @@ const { isSimpleObject, isNotEmpty } = require('../../../lib/util/objects')
const fixtures = [
{ name: 'populated object', value: { a: 1, b: 2, c: 3 }, simple: true, nonEmpty: true },
{ name: 'empty object', value: {}, simple: true, nonEmpty: false },
{ name: 'object', value: { key: 'value' }, simple: true, nonEmpty: true },
{ name: 'null', value: null, simple: false, nonEmpty: false },
{ name: 'undefined', value: undefined, simple: false, nonEmpty: false },
{ name: 'array', value: [1, 2, 3, 4], simple: true, nonEmpty: true },
{ name: 'empty array', value: [], simple: true, nonEmpty: false },
{ name: 'array', value: [1, 2, 3, 4], simple: false, nonEmpty: false },
{ name: 'empty array', value: [], simple: false, nonEmpty: false },
{ name: 'string', value: 'a string', simple: false, nonEmpty: false },
{ name: 'empty string', value: '', simple: false, nonEmpty: false },
{ name: 'number', value: 42, simple: false, nonEmpty: false },
Expand Down

0 comments on commit 8baa5bc

Please sign in to comment.