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

Fix cuid check #14

Merged
merged 1 commit into from
Jun 6, 2024
Merged

Fix cuid check #14

merged 1 commit into from
Jun 6, 2024

Conversation

stormshield-kg
Copy link
Contributor

@stormshield-kg stormshield-kg commented May 15, 2024

Fixes the following test:

assert!(!cuid2::is_cuid2("aaa_1aaa"));

Also fixes some clippy warnings and a panic in debug when length=0.

@mplanchard
Copy link
Owner

Thanks for the PR, and sorry for the slow response! I was on vacation, and it's been a busy month.

Am I correct that the main change to the is_cuid() function is to ensure the CUID only contains valid base 36 characters? I think that's a good change. I see that we're using is_ascii_lowercase() now instead of checking against the STARTING_CHARACTERS. While these are equivalent, I would prefer we continue to check against STARTING_CHARACTERS, since that const is what's used to generate the CUID. Using it in the check means that if it changes at some point in the future, we won't need to change the check as well.

Regarding the change to not panic when length = 0, I'm of the opinion that a 0-length CUID is a user error and panicking is appropriate, especially given that our is_cuid() check explicitly says that anything of length < 2 is not a valid CUID. We could make the error more explicit, though. Would you mind throwing a check for that in the CuidConstructor::with_length() method and panicking with a reasonble error message if the length is < 2?

@stormshield-kg
Copy link
Contributor Author

Fixed.

@mplanchard mplanchard merged commit dcb2dc0 into mplanchard:master Jun 6, 2024
58 checks passed
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.

None yet

2 participants