3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-12-23 23:00:35 +01:00

Allow empty channel names (but not namespaces).

Dieser Commit ist enthalten in:
Andrew Steinborn 2019-04-21 02:52:30 -04:00
Ursprung 7a5d8d424a
Commit dea7c215d7
2 geänderte Dateien mit 29 neuen und 2 gelöschten Zeilen

Datei anzeigen

@ -12,7 +12,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
*/
public final class MinecraftChannelIdentifier implements ChannelIdentifier {
private static final Pattern VALID_IDENTIFIER_REGEX = Pattern.compile("[a-z0-9\\-_]+");
private static final Pattern VALID_IDENTIFIER_REGEX = Pattern.compile("[a-z0-9\\-_]*");
private final String namespace;
private final String name;
@ -42,7 +42,7 @@ public final class MinecraftChannelIdentifier implements ChannelIdentifier {
*/
public static MinecraftChannelIdentifier create(String namespace, String name) {
Preconditions.checkArgument(!Strings.isNullOrEmpty(namespace), "namespace is null or empty");
Preconditions.checkArgument(!Strings.isNullOrEmpty(name), "namespace is null or empty");
Preconditions.checkArgument(name != null, "namespace is null or empty");
Preconditions.checkArgument(VALID_IDENTIFIER_REGEX.matcher(namespace).matches(),
"namespace is not valid");
Preconditions

Datei anzeigen

@ -0,0 +1,27 @@
package com.velocitypowered.api.proxy.messages;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
class MinecraftChannelIdentifierTest {
@Test
void createAllowsValidNamespaces() {
MinecraftChannelIdentifier.create("minecraft", "brand");
}
@Test
void createAllowsEmptyName() {
MinecraftChannelIdentifier.create("minecraft", "");
}
@Test
void createDisallowsNull() {
assertAll(
() -> assertThrows(IllegalArgumentException.class, () -> MinecraftChannelIdentifier.create(null, "")),
() -> assertThrows(IllegalArgumentException.class, () -> MinecraftChannelIdentifier.create("", "")),
() -> assertThrows(IllegalArgumentException.class, () -> MinecraftChannelIdentifier.create("minecraft", null))
);
}
}