Joi: uri validation fails for a correct url

Created on 9 Jun 2017  路  2Comments  路  Source: sideway/joi

Context

  • node version: 6.9.4
  • joi version: 10.5.2
  • environment (node, browser): node
  • used with (hapi, standalone, ...): standalone
  • any other relevant information:

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

I want to validate a JSON with an url parameter.

const schema = joi.object().keys({
    imageUrl: joi.string().uri().trim().required(),
});

The following URL does fail.
https://images.internetstores.de/products//517873/02/ca8433/Keen_Oakridge_WP_Shoes_Women_Magnet_Rose[1000x700].jpg?forceSize=true&forceAspectRatio=true

The error is
child "imageUrl" fails because ["imageUrl" must be a valid uri]
but as you can easily verify, the url is valid.

Which result you had ?

Validation failed.

What did you expect ?

Validation succeeds.

non issue

Most helpful comment

And since this has come up before:
just because a url resolves and loads a resource does not mean it is a valid uri per the RFCs. And RFCs rule all. :)

All 2 comments

It is indeed invalid as per RFC mentioned in the docs. The brackets should be percent encoded.

And since this has come up before:
just because a url resolves and loads a resource does not mean it is a valid uri per the RFCs. And RFCs rule all. :)

Was this page helpful?
0 / 5 - 0 ratings