mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-09-29 05:47:27 +02:00
Handle invalid empty command inputs (#3606)
This commit is contained in:
parent
1fb62d2616
commit
85a49f0f44
@ -79,6 +79,7 @@ public interface DisplayNameNode extends ScopedNode<DisplayNameNode, DisplayName
|
||||
*
|
||||
* @param displayName the display name
|
||||
* @return the builder
|
||||
* @throws IllegalArgumentException if {@code displayName} is empty
|
||||
*/
|
||||
@NonNull Builder displayName(@NonNull String displayName);
|
||||
|
||||
|
@ -96,6 +96,7 @@ public interface InheritanceNode extends ScopedNode<InheritanceNode, Inheritance
|
||||
*
|
||||
* @param group the group name
|
||||
* @return the builder
|
||||
* @throws IllegalArgumentException if {@code group} is not a valid group name
|
||||
*/
|
||||
@NonNull Builder group(@NonNull String group);
|
||||
|
||||
|
@ -87,6 +87,7 @@ public interface MetaNode extends ScopedNode<MetaNode, MetaNode.Builder> {
|
||||
*
|
||||
* @param key the meta key
|
||||
* @return the builder
|
||||
* @throws IllegalArgumentException if {@code key} is empty
|
||||
*/
|
||||
@NonNull Builder key(@NonNull String key);
|
||||
|
||||
|
@ -104,6 +104,7 @@ public interface PermissionNode extends ScopedNode<PermissionNode, PermissionNod
|
||||
*
|
||||
* @param permission the permission
|
||||
* @return the builder
|
||||
* @throws IllegalArgumentException if {@code permission} is empty
|
||||
*/
|
||||
@NonNull Builder permission(@NonNull String permission);
|
||||
|
||||
|
@ -101,6 +101,7 @@ public interface RegexPermissionNode extends ScopedNode<RegexPermissionNode, Reg
|
||||
*
|
||||
* @param pattern the pattern
|
||||
* @return the builder
|
||||
* @throws IllegalArgumentException if {@code pattern} is empty
|
||||
*/
|
||||
@NonNull Builder pattern(@NonNull String pattern);
|
||||
|
||||
|
@ -66,6 +66,11 @@ public class MetaSet extends GenericChildCommand {
|
||||
String value = args.get(1);
|
||||
MutableContextSet context = args.getContextOrDefault(2, plugin);
|
||||
|
||||
if (key.isEmpty()) {
|
||||
Message.INVALID_META_KEY_EMPTY.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ArgumentPermissions.checkContext(plugin, sender, permission, context) ||
|
||||
ArgumentPermissions.checkGroup(plugin, sender, target, context) ||
|
||||
ArgumentPermissions.checkArguments(plugin, sender, permission, key)) {
|
||||
|
@ -71,6 +71,11 @@ public class MetaSetTemp extends GenericChildCommand {
|
||||
TemporaryNodeMergeStrategy modifier = args.getTemporaryModifierAndRemove(3).orElseGet(() -> plugin.getConfiguration().get(ConfigKeys.TEMPORARY_ADD_BEHAVIOUR));
|
||||
MutableContextSet context = args.getContextOrDefault(3, plugin);
|
||||
|
||||
if (key.isEmpty()) {
|
||||
Message.INVALID_META_KEY_EMPTY.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ArgumentPermissions.checkContext(plugin, sender, permission, context) ||
|
||||
ArgumentPermissions.checkGroup(plugin, sender, target, context) ||
|
||||
ArgumentPermissions.checkArguments(plugin, sender, permission, key)) {
|
||||
|
@ -62,6 +62,11 @@ public class MetaUnset extends GenericChildCommand {
|
||||
String key = args.get(0);
|
||||
MutableContextSet context = args.getContextOrDefault(1, plugin);
|
||||
|
||||
if (key.isEmpty()) {
|
||||
Message.INVALID_META_KEY_EMPTY.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ArgumentPermissions.checkContext(plugin, sender, permission, context) ||
|
||||
ArgumentPermissions.checkGroup(plugin, sender, target, context) ||
|
||||
ArgumentPermissions.checkArguments(plugin, sender, permission, key)) {
|
||||
|
@ -62,6 +62,11 @@ public class MetaUnsetTemp extends GenericChildCommand {
|
||||
String key = args.get(0);
|
||||
MutableContextSet context = args.getContextOrDefault(1, plugin);
|
||||
|
||||
if (key.isEmpty()) {
|
||||
Message.INVALID_META_KEY_EMPTY.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ArgumentPermissions.checkContext(plugin, sender, permission, context) ||
|
||||
ArgumentPermissions.checkGroup(plugin, sender, target, context) ||
|
||||
ArgumentPermissions.checkArguments(plugin, sender, permission, key)) {
|
||||
|
@ -72,6 +72,10 @@ public class PermissionCheck extends GenericChildCommand {
|
||||
}
|
||||
|
||||
String node = args.get(0);
|
||||
if (node.isEmpty()) {
|
||||
Message.INVALID_PERMISSION_EMPTY.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
// accumulate nodes
|
||||
List<Node> own = new ArrayList<>();
|
||||
|
@ -67,7 +67,8 @@ public class PermissionSet extends GenericChildCommand {
|
||||
MutableContextSet context = args.getContextOrDefault(2, plugin);
|
||||
|
||||
if (node.isEmpty()) {
|
||||
Message.PERMISSION_INVALID_ENTRY_EMPTY.send(sender);
|
||||
Message.INVALID_PERMISSION_EMPTY.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ArgumentPermissions.checkContext(plugin, sender, permission, context) ||
|
||||
|
@ -72,7 +72,8 @@ public class PermissionSetTemp extends GenericChildCommand {
|
||||
MutableContextSet context = args.getContextOrDefault(3, plugin);
|
||||
|
||||
if (node.isEmpty()) {
|
||||
Message.PERMISSION_INVALID_ENTRY_EMPTY.send(sender);
|
||||
Message.INVALID_PERMISSION_EMPTY.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ArgumentPermissions.checkContext(plugin, sender, permission, context) ||
|
||||
|
@ -66,7 +66,8 @@ public class PermissionUnset extends GenericChildCommand {
|
||||
MutableContextSet context = args.getContextOrDefault(1, plugin);
|
||||
|
||||
if (node.isEmpty()) {
|
||||
Message.PERMISSION_INVALID_ENTRY_EMPTY.send(sender);
|
||||
Message.INVALID_PERMISSION_EMPTY.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ArgumentPermissions.checkContext(plugin, sender, permission, context) ||
|
||||
|
@ -69,7 +69,8 @@ public class PermissionUnsetTemp extends GenericChildCommand {
|
||||
MutableContextSet context = args.getContextOrDefault(fromIndex, plugin);
|
||||
|
||||
if (node.isEmpty()) {
|
||||
Message.PERMISSION_INVALID_ENTRY_EMPTY.send(sender);
|
||||
Message.INVALID_PERMISSION_EMPTY.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ArgumentPermissions.checkContext(plugin, sender, permission, context) ||
|
||||
|
@ -50,6 +50,7 @@ import me.lucko.luckperms.common.model.manager.group.GroupManager;
|
||||
import me.lucko.luckperms.common.node.types.Inheritance;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.sender.Sender;
|
||||
import me.lucko.luckperms.common.storage.misc.DataConstraints;
|
||||
import me.lucko.luckperms.common.util.Predicates;
|
||||
|
||||
import net.luckperms.api.actionlog.Action;
|
||||
@ -72,6 +73,10 @@ public class DeleteGroup extends SingleCommand {
|
||||
}
|
||||
|
||||
String groupName = args.get(0).toLowerCase(Locale.ROOT);
|
||||
if (!DataConstraints.GROUP_NAME_TEST.test(groupName)) {
|
||||
Message.GROUP_INVALID_ENTRY.send(sender, groupName);
|
||||
return;
|
||||
}
|
||||
|
||||
if (groupName.equalsIgnoreCase(GroupManager.DEFAULT_GROUP_NAME)) {
|
||||
Message.DELETE_GROUP_ERROR_DEFAULT.send(sender);
|
||||
|
@ -64,6 +64,11 @@ public class GroupSetDisplayName extends ChildCommand<Group> {
|
||||
String name = args.get(0);
|
||||
ImmutableContextSet context = args.getContextOrDefault(1, plugin).immutableCopy();
|
||||
|
||||
if (name.isEmpty()) {
|
||||
Message.INVALID_DISPLAY_NAME_EMPTY.send(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
String previousName = target.normalData().nodesInContext(context).stream()
|
||||
.filter(NodeType.DISPLAY_NAME::matches)
|
||||
.map(NodeType.DISPLAY_NAME::cast)
|
||||
|
@ -2200,13 +2200,18 @@ public interface Message {
|
||||
.append(FULL_STOP)
|
||||
);
|
||||
|
||||
Args0 PERMISSION_INVALID_ENTRY_EMPTY = () -> prefixed(translatable()
|
||||
// "&cThe empty string is not a valid permission."
|
||||
.key("luckperms.command.misc.permission-invalid-empty")
|
||||
Args1<String> INVALID_INPUT_EMPTY = s -> prefixed(translatable()
|
||||
// "&cThe empty string is not a valid {s}."
|
||||
.key("luckperms.command.misc.invalid-input-empty-" + s)
|
||||
.color(RED)
|
||||
.append(FULL_STOP)
|
||||
);
|
||||
|
||||
// Predefined shorthands for the above message
|
||||
Args0 INVALID_PERMISSION_EMPTY = () -> INVALID_INPUT_EMPTY.build("permission");
|
||||
Args0 INVALID_META_KEY_EMPTY = () -> INVALID_INPUT_EMPTY.build("meta-key");
|
||||
Args0 INVALID_DISPLAY_NAME_EMPTY = () -> INVALID_INPUT_EMPTY.build("display-name");
|
||||
|
||||
Args3<PermissionHolder, Group, ContextSet> SET_INHERIT_SUCCESS = (holder, parent, context) -> prefixed(translatable()
|
||||
// "&b{}&a now inherits permissions from &b{}&a in context {}&a."
|
||||
.key("luckperms.command.generic.parent.add")
|
||||
|
@ -95,7 +95,11 @@ public class DisplayName extends AbstractNode<DisplayNameNode, DisplayNameNode.B
|
||||
|
||||
@Override
|
||||
public @NonNull Builder displayName(@NonNull String displayName) {
|
||||
this.displayName = Objects.requireNonNull(displayName, "displayName");
|
||||
Objects.requireNonNull(displayName, "displayName");
|
||||
if (displayName.isEmpty()) {
|
||||
throw new IllegalArgumentException("display name is empty");
|
||||
}
|
||||
this.displayName = displayName;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -28,6 +28,7 @@ package me.lucko.luckperms.common.node.types;
|
||||
import me.lucko.luckperms.common.node.AbstractNode;
|
||||
import me.lucko.luckperms.common.node.AbstractNodeBuilder;
|
||||
|
||||
import me.lucko.luckperms.common.storage.misc.DataConstraints;
|
||||
import net.luckperms.api.context.ImmutableContextSet;
|
||||
import net.luckperms.api.model.group.Group;
|
||||
import net.luckperms.api.node.metadata.NodeMetadataKey;
|
||||
@ -97,7 +98,11 @@ public class Inheritance extends AbstractNode<InheritanceNode, InheritanceNode.B
|
||||
|
||||
@Override
|
||||
public @NonNull Builder group(@NonNull String group) {
|
||||
this.groupName = Objects.requireNonNull(group, "group");
|
||||
Objects.requireNonNull(group, "group");
|
||||
if (!DataConstraints.GROUP_NAME_TEST.test(group)) {
|
||||
throw new IllegalArgumentException("group name is invalid");
|
||||
}
|
||||
this.groupName = group;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -62,7 +62,9 @@ luckperms.command.misc.webapp-unable-to-communicate=Unable to communicate with t
|
||||
luckperms.command.misc.check-console-for-errors=Check the console for errors
|
||||
luckperms.command.misc.file-must-be-in-data=File {0} must be a direct child of the data directory
|
||||
luckperms.command.misc.wait-to-finish=Please wait for it to finish and try again
|
||||
luckperms.command.misc.permission-invalid-empty=The empty string is not a valid permission
|
||||
luckperms.command.misc.invalid-input-empty-permission=The empty string is not a valid permission
|
||||
luckperms.command.misc.invalid-input-empty-meta-key=The empty string is not a valid meta key
|
||||
luckperms.command.misc.invalid-input-empty-display-name=The empty string is not a valid display name
|
||||
luckperms.command.misc.invalid-priority=Invalid priority {0}
|
||||
luckperms.command.misc.expected-number=Expected a number
|
||||
luckperms.command.misc.date-parse-error=Could not parse date {0}
|
||||
|
@ -48,7 +48,6 @@ public class NodeParseTest {
|
||||
@CsvSource({
|
||||
"group.test, test",
|
||||
"group.TEST, test",
|
||||
"group.hello world, hello world"
|
||||
})
|
||||
public void testInheritance(String key, String expectedGroupName) {
|
||||
Inheritance.Builder builder = Inheritance.parse(key);
|
||||
@ -68,6 +67,14 @@ public class NodeParseTest {
|
||||
assertNull(builder);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {
|
||||
"group.hello world"
|
||||
})
|
||||
public void testInheritanceThrows(String key) {
|
||||
assertThrows(IllegalArgumentException.class, () -> Inheritance.parse(key));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({
|
||||
"displayname.test, test",
|
||||
@ -92,6 +99,14 @@ public class NodeParseTest {
|
||||
assertNull(builder);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {
|
||||
"displayname."
|
||||
})
|
||||
public void testDisplayNameThrows(String key) {
|
||||
assertThrows(IllegalArgumentException.class, () -> DisplayName.parse(key));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({
|
||||
"weight.100, 100",
|
||||
|
Loading…
Reference in New Issue
Block a user