SHA256
Сервер: уточнить правила имён каналов и поиск треда
This commit is contained in:
@@ -8,6 +8,10 @@ public final class ChannelNameRules {
|
||||
private static final int MAX_DISPLAY_NAME_LENGTH = 32;
|
||||
private static final Pattern DISPLAY_ALLOWED_PATTERN =
|
||||
Pattern.compile("^[A-Za-z0-9_-]+$");
|
||||
private static final Pattern PUBLIC_CHANNEL_ALLOWED_PATTERN =
|
||||
Pattern.compile("^[A-Za-z0-9_-]+$");
|
||||
private static final Pattern DIGITS_ONLY_PATTERN =
|
||||
Pattern.compile("^[0-9]+$");
|
||||
|
||||
private ChannelNameRules() {}
|
||||
|
||||
@@ -34,6 +38,17 @@ public final class ChannelNameRules {
|
||||
return normalized;
|
||||
}
|
||||
|
||||
public static String requireValidPublicDisplayNameForCreate(String rawName) {
|
||||
String normalized = requireValidDisplayNameForCreate(rawName);
|
||||
if (!PUBLIC_CHANNEL_ALLOWED_PATTERN.matcher(normalized).matches()) {
|
||||
throw new IllegalArgumentException("channelName contains unsupported characters");
|
||||
}
|
||||
if (DIGITS_ONLY_PATTERN.matcher(normalized).matches()) {
|
||||
throw new IllegalArgumentException("channelName must not contain only digits");
|
||||
}
|
||||
return normalized;
|
||||
}
|
||||
|
||||
public static String toCanonicalSlug(String rawName) {
|
||||
String normalized = normalizeDisplayName(rawName);
|
||||
if (normalized.isEmpty()) {
|
||||
|
||||
Reference in New Issue
Block a user