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

count string length correctly in OpenAPI validators #666

Merged
merged 1 commit into from
Nov 18, 2023
Merged

count string length correctly in OpenAPI validators #666

merged 1 commit into from
Nov 18, 2023

Conversation

mishmish-dev
Copy link
Contributor

@mishmish-dev mishmish-dev commented Oct 5, 2023

Currently in the poem's OpenAPI module, derived maxLength and minLength validators use str::len() method, which counts UTF-8 bytes, not Unicode characters in string. While JSON Schema spec defines maxLength and minLength for number of characters.

This pull request fixes that, also adding extra couple unit tests to better cover edge cases.

@attila-lin
Copy link
Collaborator

r? @sunli829

@mishmish-dev
Copy link
Contributor Author

mishmish-dev commented Oct 8, 2023

Hi! I want to leave an extra remark.

The proposed implementation assumes that character in Unicode string is the same as Unicode code point, which, I think, is pretty reasonable in the context of web APIs.

However, I am not completely sure it is precisely JSON Schema / JSON specs' interpretation. (For example, is Indonesian flag emoji 🇮🇩 one character or two?)

@sunli829 sunli829 merged commit 0a1dc1e into poem-web:master Nov 18, 2023
7 checks passed
@sunli829
Copy link
Collaborator

thanks

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

Successfully merging this pull request may close these issues.

3 participants