hapijs / hoek

Node utilities shared among the extended hapi universe
Other
481 stars 171 forks source link

Fix applyToDefaults to work better with non-object source values #365

Closed watson closed 3 years ago

watson commented 3 years ago

Without this change the test would throw the following exception:

Cannot use 'in' operator to search for 'b' in undefined

at Object.internals.reachCopy (/Users/watson/code/node_modules/@hapi/hoek/lib/applyToDefaults.js:76:23)
at Object.internals.applyToDefaultsWithShallow (/Users/watson/code/node_modules/@hapi/hoek/lib/applyToDefaults.js:66:19)
at Object.module.exports [as applyToDefaults] (/Users/watson/code/node_modules/@hapi/hoek/lib/applyToDefaults.js:23:26)
at /Users/watson/code/node_modules/@hapi/hoek/test/index.js:654:29
at Immediate.<anonymous> (/Users/watson/code/node_modules/@hapi/hoek/node_modules/@hapi/lab/lib/runner.js:661:35)
at processImmediate (internal/timers.js:461:21)

I discovered this issue when registering a route in hapi like so:

server.route({
  method: 'GET',
  path: '/',
  handler: () => 'ok',
  options: {
    validate: undefined
  }
})

The fact that validate is undefined will make this call to route throw.

devinivy commented 3 years ago

Just want to say I have been following this and am cheering you all on from the sidelines ✨ Thanks for taking the time!

watson commented 3 years ago

Is this PR ready to merge, or have I missed a review comment I still need to address?