From a1e239d08c878d4dcdaf841e9c34169124e62cb1 Mon Sep 17 00:00:00 2001 From: zml2008 Date: Sat, 24 Dec 2011 22:04:37 -0800 Subject: [PATCH] Fixed SIOOBE when entering a blank quoted string --- .../sk89q/minecraft/util/commands/CommandContext.java | 7 ++++++- .../com/sk89q/wepif/PermissionsResolverManager.java | 4 ++-- .../minecraft/util/commands/CommandContextTest.java | 11 +++++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/sk89q/minecraft/util/commands/CommandContext.java b/src/main/java/com/sk89q/minecraft/util/commands/CommandContext.java index 7a73fe09c..52a708cfd 100644 --- a/src/main/java/com/sk89q/minecraft/util/commands/CommandContext.java +++ b/src/main/java/com/sk89q/minecraft/util/commands/CommandContext.java @@ -64,7 +64,7 @@ public class CommandContext { List argList = new ArrayList(args.length); for (int i = 1; i < args.length; ++i) { String arg = args[i]; - if (arg.isEmpty()) { + if (arg.length() == 0) { continue; } @@ -94,6 +94,11 @@ public class CommandContext { arg = build.toString(); i = endIndex; } + + // In case there is an empty quoted string + if (arg.length() == 0) { + continue; + } // else raise exception about hanging quotes? } argList.add(arg); diff --git a/src/main/java/com/sk89q/wepif/PermissionsResolverManager.java b/src/main/java/com/sk89q/wepif/PermissionsResolverManager.java index 2f7257476..1bbc479c0 100644 --- a/src/main/java/com/sk89q/wepif/PermissionsResolverManager.java +++ b/src/main/java/com/sk89q/wepif/PermissionsResolverManager.java @@ -241,8 +241,8 @@ public class PermissionsResolverManager implements PermissionsResolver { } if (keys.contains("dinner-perms") || keys.contains("dinnerperms")) { - config.setProperty("dinner-perms", null); - config.setProperty("dinnerperms", null); + config.removeProperty("dinner-perms"); + config.removeProperty("dinnerperms"); isUpdated = true; } if (!keys.contains("permissions")) { diff --git a/src/test/java/com/sk89q/minecraft/util/commands/CommandContextTest.java b/src/test/java/com/sk89q/minecraft/util/commands/CommandContextTest.java index 88b26aa98..ddad60281 100644 --- a/src/test/java/com/sk89q/minecraft/util/commands/CommandContextTest.java +++ b/src/test/java/com/sk89q/minecraft/util/commands/CommandContextTest.java @@ -143,4 +143,15 @@ public class CommandContextTest { fail("Error creating CommandContext"); } } + + @Test + public void testEmptyQuote() { + try { + CommandContext context = new CommandContext("region flag xmas blocked-cmds \"\""); + assertEquals(context.argsLength(), 3); + } catch (CommandException e) { + e.printStackTrace(); + fail("Error creating CommandContext"); + } + } }