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

Support for UTF-16 length validation #162

Open
gobanos opened this issue Jul 25, 2024 · 0 comments
Open

Support for UTF-16 length validation #162

gobanos opened this issue Jul 25, 2024 · 0 comments

Comments

@gobanos
Copy link

gobanos commented Jul 25, 2024

Context

We are using nutype to replicate our frontend validators in the backend.
One tricky aspect is string length validation.

In the javascript frontend we use .length to validate the strings which is the length of the UTF-16 string in javascript engine.

Currently we are using custom validators for that purpose, like so

#[nutype(
    validate(not_empty, predicate = |t| t.encode_utf16().count() <= 255),
)]
pub struct ValidTitle(String);

Suggestions

We'd be interested in either alternative string validators len_utf16_max & len_utf16_min or an extra parameter to the string length validator with the encoding.

Thanks for that great lib 😊

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

1 participant