Open ayoo opened 3 weeks ago
This turned out that the backslash in the pattern needed to be escaped like this pattern:
^[\\p{L}]+([\\p{L} '-][\\p{L}]+)*$
then it works all good.
The only issue with this is the default error message without 'patternDescription' containing the extra backslash as well.
"$schema": "http://localhost:8080/schemas/ErrorModel.json",
"title": "Unprocessable Entity",
"status": 422,
"detail": "validation failed",
"errors": [
{
"message": "expected string to match pattern ^[\\p{L}]+([\\p{L} '-][\\p{L}]+)*$",
"location": "body.firstName",
"value": "11111"
}
]
}
@ayoo glad you figured it out! The extra backslash in the returned JSON is because of the JSON encoder I believe, for example take a look at:
https://go.dev/play/p/-Qz6io2G89d
If this gets parsed and displayed somewhere it should just have the one backslash.
The pattern attribute used to validate input values with regex sometimes doesn't work, allowing invalid requests to get through.
Here is my test script.
When '111111' was provided as a firstName and it still passes the validation.
The pattern matching works in Go and tested as shown here.
Example
Is this a bug or am I missing something here?
Thanks in advance.