-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Description
Context
- node version: 4.2.1
- joi version: 7.3.0
- environment: node
- used with: Koa
What am I trying to achieve?
I'm trying to validate and coerce query parameters of incoming http requests. I'm validating a object that is the result of parsing the query string (handled by Koa).
Reproduction
const Joi = require('joi')
const types = ['ph', 'nitrate', 'nitrite']
const schema = Joi.object({
type: Joi.array().items(
Joi.string().only(types)
).single().min(1).required(),
from: Joi.date().required(),
to: Joi.date().default(() => new Date(), 'Current time')
})
const query = {
// An example of an incorrectly formed array of strings
type: '["foo", "bar]',
from: 'Wed Feb 17 2016 14:48:10 GMT-0500 (EST)',
}
try {
const validatedQuery = Joi.attempt(query, schema)
console.log(validatedQuery)
} catch (e) {
console.error(e.message)
console.error(e.stack)
}TypeError: cannot delete property '0' of [object String]
at Error.internals.Err.toString.internals.getPath.internals.serializer.internals.annotate.internals.safeStringify.replace [as annotate] (/Users/louis/code/grove/api/node_modules/joi/lib/errors.js:264:40)
at root.attempt (/Users/louis/code/grove/api/node_modules/joi/lib/index.js:136:39)
at Object.<anonymous> (/Users/louis/code/grove/api/repro.js:19:30)
at Module._compile (module.js:435:26)
at Object.Module._extensions..js (module.js:442:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:311:12)
at Function.Module.runMain (module.js:467:10)
at startup (node.js:134:18)
at node.js:961:3The error is coming from this line. I'm not quite sure why it's throwing, as I can run delete 'foobar'[0] and delete 'foobar'['0'] in a Node REPL without throwing an exception.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugBug or defectBug or defect