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

Format null value on error messages #144

Open
EVDW opened this issue Oct 22, 2024 · 1 comment
Open

Format null value on error messages #144

EVDW opened this issue Oct 22, 2024 · 1 comment

Comments

@EVDW
Copy link

EVDW commented Oct 22, 2024

Version used: 2.3.0

Problem description:
When using a custom error message with the argument {data:value} in the error message template, if the data value is null, the error message will contains the string "{data:value}" instead of just nothing.

How to reproduce:
Here is a schema configuration with:

'$error' => [
    'type' => 'The data should be a valid resource identifier ({expected}), "{data:value}" ({data:type}) given.',
]

Let's say a null value is given to the schema, the rendered error message will return:
The data should be a valid resource identifier (integer), "{data:value}" (null) given.

The expected return should be:
The data should be a valid resource identifier (integer), "" (null) given.

Issue:
The issue is in the ErrorFormatter where the key to replaced is searched with an isset function. But isset determine if a variable is declared and is different than null, which is the problem. The array_key_exists function should be better in order to get null values and to replace the key in the error template message.

@sorinsarca
Copy link
Member

I will add a fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants