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

Missing Support For Unicode Character Classes #1442

Closed
3 tasks done
Car-ElWilliams opened this issue Jun 22, 2023 · 2 comments
Closed
3 tasks done

Missing Support For Unicode Character Classes #1442

Car-ElWilliams opened this issue Jun 22, 2023 · 2 comments
Labels

Comments

@Car-ElWilliams
Copy link

Car-ElWilliams commented Jun 22, 2023

Sorting

  • I'm submitting a ...

    • bug request
    • feature request
  • I confirm that I

    • used the search to make sure that a similar issue hasn't already been submit

Expected Behavior

I am implementing regex validation via the pattern keyword annotation for my api:

/**
 * Allows for more generic naming, but disallows general punctuation, line breaks and non unicode letters/numbers
 * @pattern ^[\p{N}\p{L}\h]{0,62}$ Generic name failed validation pattern
 */

type GenericName = string

The provided @pattern regex with it's provided unicode classes (e.g. \p{L}) should match generic names such as: Müller, Åman, Project 123 etc and throw an error if the request string is invalid.

Current Behavior

It seems that unicode classes are not supported by whatever regex engine TSOA runs on, since my api throws the @pattern's error message even though the request parameter string is clearly valid. However, If I exchange the regex pattern with a non unicode regex (^[a-zA-Z0-9-\h]*$ or anything similar) the validation works as intended.

Attempted Solutions

I have double checked that the regex is correct
I have tried adding the /u (unicode) flag to my regex
I have also tried removing the escaping backslash generated by TSOA in the swagger.json file, but to no avail.

Maintainer Note

If unicode regex is supported please provide a working example, if not then we would greatly desire such a feature since we use a lot of regex validation with unicode for our api.

Swagger File

The auto generated swagger.json file looks like this:

"schemas": {
  "GenericName": {
  "type": "string",
  "description": "Allows for more generic naming, but disallows general punctuation and line breaks and non unicode letters/numbers",
  "pattern": "^[\\p{N}\\p{L}\\h]{0,62}$"
 }
}

Context (Environment)

Version of the library: 4.1.3
Version of NodeJS: 16.14.2
Package manager: npm

@github-actions
Copy link

Hello there Car-ElWilliams 👋

Thank you for opening your very first issue in this project.

We will try to get back to you as soon as we can.👀

@github-actions
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

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

No branches or pull requests

1 participant