Restrict username minimum length too (3 chars)

This commit is contained in:
Henrik Rydgård committed 2025-01-07 18:09:19 +01:00
1 parent 77e575dd65
commit 6ebbb434e4
7 files changed
+19 -9

No files matched your search

+9 -1
View File
@@ -105,7 +105,7 @@ int countChar(std::string_view haystack, char needle) {
return count;
}
std::string SanitizeString(std::string_view input, StringRestriction restriction, int maxLength) {
std::string SanitizeString(std::string_view input, StringRestriction restriction, int minLength, int maxLength) {
if (restriction == StringRestriction::None) {
return std::string(input);
}
@@ -127,6 +127,14 @@ std::string SanitizeString(std::string_view input, StringRestriction restriction
}
}
if (minLength >= 0) {
if (sanitized.size() < minLength) {
// Just reject it by returning an empty string, as we can't really
// conjure up new characters here.
return std::string();
}
}
if (maxLength >= 0) {
// TODO: Cut at whole UTF-8 chars!
if (sanitized.size() > maxLength) {