Ease handling of group names containing spaces, after a faulty migration process

This commit is contained in:
Luck 2016-12-19 21:50:22 +00:00
parent 060fa6e5f7
commit 1bdb512826
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
5 changed files with 15 additions and 2 deletions

View File

@ -57,7 +57,7 @@ public class ParentRemove extends SharedSubCommand {
@Override @Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args, String label) throws CommandException { public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args, String label) throws CommandException {
String groupName = ArgumentUtils.handleName(0, args); String groupName = ArgumentUtils.handleNameWithSpace(0, args);
String server = ArgumentUtils.handleServer(1, args); String server = ArgumentUtils.handleServer(1, args);
String world = ArgumentUtils.handleWorld(2, args); String world = ArgumentUtils.handleWorld(2, args);

View File

@ -56,7 +56,7 @@ public class ParentRemoveTemp extends SharedSubCommand {
@Override @Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args, String label) throws CommandException { public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args, String label) throws CommandException {
String groupName = ArgumentUtils.handleName(0, args); String groupName = ArgumentUtils.handleNameWithSpace(0, args);
String server = ArgumentUtils.handleServer(1, args); String server = ArgumentUtils.handleServer(1, args);
String world = ArgumentUtils.handleWorld(2, args); String world = ArgumentUtils.handleWorld(2, args);

View File

@ -65,6 +65,14 @@ public class ArgumentUtils {
return groupName; return groupName;
} }
public static String handleNameWithSpace(int index, List<String> args) throws ArgumentException {
String groupName = args.get(index).toLowerCase();
if (ArgumentChecker.checkNameWithSpace(groupName)) {
throw new DetailedUsageException();
}
return groupName;
}
public static boolean handleBoolean(int index, List<String> args) throws ArgumentException { public static boolean handleBoolean(int index, List<String> args) throws ArgumentException {
if (index < args.size()) { if (index < args.size()) {
String bool = args.get(index); String bool = args.get(index);

View File

@ -38,6 +38,7 @@ import java.util.regex.Pattern;
public class Patterns { public class Patterns {
public static final Pattern COMMAND_SEPARATOR = Pattern.compile(" (?=([^\\\"]*\\\"[^\\\"]*\\\")*[^\\\"]*$)"); public static final Pattern COMMAND_SEPARATOR = Pattern.compile(" (?=([^\\\"]*\\\"[^\\\"]*\\\")*[^\\\"]*$)");
public static final Pattern NON_ALPHA_NUMERIC = Pattern.compile("[\\/\\$\\.\\- ]"); public static final Pattern NON_ALPHA_NUMERIC = Pattern.compile("[\\/\\$\\.\\- ]");
public static final Pattern NON_ALPHA_NUMERIC_SPACE = Pattern.compile("[\\/\\$\\.\\-]");
public static final Pattern NON_USERNAME = Pattern.compile("[^A-Za-z0-9_ ]"); public static final Pattern NON_USERNAME = Pattern.compile("[^A-Za-z0-9_ ]");
public static final Pattern SHORTHAND_NODE = Pattern.compile("\\.\\([^.]+\\)"); public static final Pattern SHORTHAND_NODE = Pattern.compile("\\.\\([^.]+\\)");
public static final Pattern STRIP_COLOR_PATTERN = Pattern.compile("(?i)" + String.valueOf('§') + "[0-9A-FK-OR]"); public static final Pattern STRIP_COLOR_PATTERN = Pattern.compile("(?i)" + String.valueOf('§') + "[0-9A-FK-OR]");

View File

@ -40,6 +40,10 @@ public class ArgumentChecker {
return (s.length() > 36 || Patterns.NON_ALPHA_NUMERIC.matcher(s).find()); return (s.length() > 36 || Patterns.NON_ALPHA_NUMERIC.matcher(s).find());
} }
public static boolean checkNameWithSpace(String s) {
return (s.length() > 36 || Patterns.NON_ALPHA_NUMERIC_SPACE.matcher(s).find());
}
public static boolean checkServer(String s) { public static boolean checkServer(String s) {
return s.toLowerCase().startsWith("r=") || (s.startsWith("(") && s.endsWith(")") && s.contains("|")) || Patterns.NON_ALPHA_NUMERIC.matcher(s).find(); return s.toLowerCase().startsWith("r=") || (s.startsWith("(") && s.endsWith(")") && s.contains("|")) || Patterns.NON_ALPHA_NUMERIC.matcher(s).find();
} }