hapijs / joi

The most powerful data validation library for JS
Other
20.86k stars 1.51k forks source link

Error in types/string/index >>> AssertionError [ERR_ASSERTION]: options contain unknown keys: 0,1 #1560

Closed zeuzere closed 6 years ago

zeuzere commented 6 years ago

Context

What are you trying to achieve or the steps to reproduce ?

I use simple-auth2 and for there construtor require('simple-oauth2').create({...}) they use tokenHost: Joi.string().required().uri(['http', 'https']) and our tokenHost as a value : 'https://ourdomain.com'

Which result you had (Error)?

     **AssertionError [ERR_ASSERTION]: options contain unknown keys: 0,1**

What did you expect ?

I see ligne 285 and 286 in Types/string/index was modify with

const unknownOptions = Object.keys(uriOptions).filter((key) => !['scheme', 'allowRelative', 'relativeOnly', 'allowQuerySquareBrackets'].includes(key)); Hoek.assert(unknownOptions.length === 0, options contain unknown keys: ${unknownOptions});

but if you run result with Object.keys(['http', 'https']).... the Hoek.assert(unknownOptions.length === 0 will always be in error when they use it with a array... Because the return is [0,1] so never 0 in length ...

Question ?

Is this the behavior wanted to return error when array ? Or its a simple-auth2 error to use Array to validate ?

Ps.: 13.4.0 was working great, but since last update its broken for array...

Thx ps.: Im not in simple-auth2 team, just a user of sa2 Yves Laroche

Marsup commented 6 years ago

Duplicate of #1552.

lock[bot] commented 4 years ago

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.