Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$-sign in object keys are escaped in the ValidationError message #921

Closed
wadebiffen opened this issue Jun 12, 2016 · 6 comments
Closed

$-sign in object keys are escaped in the ValidationError message #921

wadebiffen opened this issue Jun 12, 2016 · 6 comments
Labels
breaking changes Change that can breaking existing code feature New functionality or improvement
Milestone

Comments

@wadebiffen
Copy link

Context

  • node version: 6.2.1
  • joi version: 8.4.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 am trying to validate objects with a $-sign in the key name and expect the validation error message to reference the same key name, but the $-sign is escaped in the error message (it is not escaped in the path or the _object though). I would prefer it to not be escaped when I return the ValidationError object as JSON response directly.

Is this intentional, and if so, why is it not escaped the other places?

'use strict';
const Joi = require('joi');
const schema = {
    $top: Joi.number().integer().min(1)
};
const obj = {
    $top: 0
};
let result = Joi.validate(obj, schema);
console.log(result.error);

Which result you had ?

$top is escaped to "$top"

{ ValidationError: child "$top" fails because ["$top" must be larger than or equal to 1]
  isJoi: true,
  name: 'ValidationError',
  details:
   [ { message: '"$top" must be larger than or equal to 1',
       path: '$top',
       type: 'number.min',
       context: [Object] } ],
  _object: { '$top': 0 },
  annotate: [Function] }

What did you expect ?

I expect $top to not be escaped (or escaped everywhere?)

{ ValidationError: child "$top" fails because ["$top" must be larger than or equal to 1]
  isJoi: true,
  name: 'ValidationError',
  details:
   [ { message: '"$top" must be larger than or equal to 1',
       path: '$top',
       type: 'number.min',
       context: [Object] } ],
  _object: { '$top': 0 },
  annotate: [Function] }
@rafaelcorreiapoli
Copy link

rafaelcorreiapoli commented Aug 15, 2016

I'm also facing this issue.
In my case I just want a special character on the "label" of my field.

curriculo: Joi.string().required().label('Currículo'),

But then í is escaped to í (hexadecimal representation)...
Is there any way to skip this ?

@DavidTPate
Copy link
Contributor

It looks like this is caused by this line which goes through and escapes HTML.

@zyrorl
Copy link

zyrorl commented Jan 19, 2017

Can we please have an option to disable this? It's really annoying when your app isn't even HTML based.

@sudo-suhas
Copy link

I would also appreciate it if an option could be added to disable it.

@Marsup Marsup added breaking changes Change that can breaking existing code request labels May 1, 2017
@Marsup Marsup added this to the 12.0.0 milestone Oct 7, 2017
@Marsup Marsup self-assigned this Oct 14, 2017
@Marsup Marsup closed this as completed in ba5f3c9 Oct 14, 2017
@paulmelnikow
Copy link

Thank you for this change! 💯

@lock
Copy link

lock bot commented Jan 9, 2020

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.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
breaking changes Change that can breaking existing code feature New functionality or improvement
Projects
None yet
Development

No branches or pull requests

8 participants