From 1bdb512826813cc1664612ca3315045eae564dd4 Mon Sep 17 00:00:00 2001 From: Luck Date: Mon, 19 Dec 2016 21:50:22 +0000 Subject: [PATCH] Ease handling of group names containing spaces, after a faulty migration process --- .../common/commands/generic/parent/ParentRemove.java | 2 +- .../common/commands/generic/parent/ParentRemoveTemp.java | 2 +- .../luckperms/common/commands/utils/ArgumentUtils.java | 8 ++++++++ .../me/lucko/luckperms/common/constants/Patterns.java | 1 + .../me/lucko/luckperms/common/utils/ArgumentChecker.java | 4 ++++ 5 files changed, 15 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentRemove.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentRemove.java index 04aab8a56..fb12f4f31 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentRemove.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentRemove.java @@ -57,7 +57,7 @@ public class ParentRemove extends SharedSubCommand { @Override public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List args, String label) throws CommandException { - String groupName = ArgumentUtils.handleName(0, args); + String groupName = ArgumentUtils.handleNameWithSpace(0, args); String server = ArgumentUtils.handleServer(1, args); String world = ArgumentUtils.handleWorld(2, args); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentRemoveTemp.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentRemoveTemp.java index e463b8c2e..77b72e583 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentRemoveTemp.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/parent/ParentRemoveTemp.java @@ -56,7 +56,7 @@ public class ParentRemoveTemp extends SharedSubCommand { @Override public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List args, String label) throws CommandException { - String groupName = ArgumentUtils.handleName(0, args); + String groupName = ArgumentUtils.handleNameWithSpace(0, args); String server = ArgumentUtils.handleServer(1, args); String world = ArgumentUtils.handleWorld(2, args); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/utils/ArgumentUtils.java b/common/src/main/java/me/lucko/luckperms/common/commands/utils/ArgumentUtils.java index c69e028d5..84f8c0025 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/utils/ArgumentUtils.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/utils/ArgumentUtils.java @@ -65,6 +65,14 @@ public class ArgumentUtils { return groupName; } + public static String handleNameWithSpace(int index, List 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 args) throws ArgumentException { if (index < args.size()) { String bool = args.get(index); diff --git a/common/src/main/java/me/lucko/luckperms/common/constants/Patterns.java b/common/src/main/java/me/lucko/luckperms/common/constants/Patterns.java index c35ccd35e..e2361a56e 100644 --- a/common/src/main/java/me/lucko/luckperms/common/constants/Patterns.java +++ b/common/src/main/java/me/lucko/luckperms/common/constants/Patterns.java @@ -38,6 +38,7 @@ import java.util.regex.Pattern; public class Patterns { public static final Pattern COMMAND_SEPARATOR = 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 SHORTHAND_NODE = Pattern.compile("\\.\\([^.]+\\)"); public static final Pattern STRIP_COLOR_PATTERN = Pattern.compile("(?i)" + String.valueOf('ยง') + "[0-9A-FK-OR]"); diff --git a/common/src/main/java/me/lucko/luckperms/common/utils/ArgumentChecker.java b/common/src/main/java/me/lucko/luckperms/common/utils/ArgumentChecker.java index ea8c4340b..130ab40a6 100644 --- a/common/src/main/java/me/lucko/luckperms/common/utils/ArgumentChecker.java +++ b/common/src/main/java/me/lucko/luckperms/common/utils/ArgumentChecker.java @@ -40,6 +40,10 @@ public class ArgumentChecker { 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) { return s.toLowerCase().startsWith("r=") || (s.startsWith("(") && s.endsWith(")") && s.contains("|")) || Patterns.NON_ALPHA_NUMERIC.matcher(s).find(); }