From 4faf259e6a3004afcbfbffd45523415fa2bc59a1 Mon Sep 17 00:00:00 2001 From: sovdee <10354869+sovdeeth@users.noreply.github.com> Date: Sun, 21 Jul 2024 15:26:05 -0700 Subject: [PATCH 1/3] band-aid fix for single quotes in commands --- src/main/java/ch/njol/skript/command/CommandUsage.java | 4 ++++ .../regressions/pull-6936-single quotes in commands.sk | 7 +++++++ 2 files changed, 11 insertions(+) create mode 100644 src/test/skript/tests/regressions/pull-6936-single quotes in commands.sk diff --git a/src/main/java/ch/njol/skript/command/CommandUsage.java b/src/main/java/ch/njol/skript/command/CommandUsage.java index 59b79765604..a7837a1241a 100644 --- a/src/main/java/ch/njol/skript/command/CommandUsage.java +++ b/src/main/java/ch/njol/skript/command/CommandUsage.java @@ -46,6 +46,10 @@ public class CommandUsage { */ public CommandUsage(@Nullable VariableString usage, String defaultUsage) { if (usage == null) { + // Manually escape quotes. This is not a good solution, as it doesn't handle many other issues, like % in + // commands, but in lieu of re-writing the argument parser and command logic completely, I believe this is + // a decent stop-gap measure for using " in commands. + defaultUsage = defaultUsage.replaceAll("\"", "\"\""); usage = VariableString.newInstance(defaultUsage); assert usage != null; } diff --git a/src/test/skript/tests/regressions/pull-6936-single quotes in commands.sk b/src/test/skript/tests/regressions/pull-6936-single quotes in commands.sk new file mode 100644 index 00000000000..6ab74968764 --- /dev/null +++ b/src/test/skript/tests/regressions/pull-6936-single quotes in commands.sk @@ -0,0 +1,7 @@ +command single-quotes-in-commands [""]: + trigger: + broadcast arg + +test "single-quotes-in-commands": + execute console command "single-quotes-in-commands ""success 1""" + execute console command "single-quotes-in-commands" From 2401841f2e87789e0d16b60bbc1e83dc475cadf8 Mon Sep 17 00:00:00 2001 From: sovdee <10354869+sovdeeth@users.noreply.github.com> Date: Sun, 21 Jul 2024 19:35:49 -0700 Subject: [PATCH 2/3] better tests --- .../tests/regressions/pull-6936-single quotes in commands.sk | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/test/skript/tests/regressions/pull-6936-single quotes in commands.sk b/src/test/skript/tests/regressions/pull-6936-single quotes in commands.sk index 6ab74968764..b8d8c554e64 100644 --- a/src/test/skript/tests/regressions/pull-6936-single quotes in commands.sk +++ b/src/test/skript/tests/regressions/pull-6936-single quotes in commands.sk @@ -1,7 +1,10 @@ command single-quotes-in-commands [""]: trigger: - broadcast arg + set {sqic::output} to arg test "single-quotes-in-commands": execute console command "single-quotes-in-commands ""success 1""" + assert {sqic::output} is "success 1" with "failed to parse arg in quotes" execute console command "single-quotes-in-commands" + assert {sqic::output} is "success 2" with "failed to use default arg" + delete {sqic::output} From ff46c2d6cc7358c3ec4eac533f475614ba3aee09 Mon Sep 17 00:00:00 2001 From: sovdee <10354869+sovdeeth@users.noreply.github.com> Date: Wed, 14 Aug 2024 15:40:10 -0700 Subject: [PATCH 3/3] use quote() instead of replaceAll() --- src/main/java/ch/njol/skript/command/CommandUsage.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/command/CommandUsage.java b/src/main/java/ch/njol/skript/command/CommandUsage.java index a7837a1241a..c746d93cf8a 100644 --- a/src/main/java/ch/njol/skript/command/CommandUsage.java +++ b/src/main/java/ch/njol/skript/command/CommandUsage.java @@ -49,7 +49,7 @@ public CommandUsage(@Nullable VariableString usage, String defaultUsage) { // Manually escape quotes. This is not a good solution, as it doesn't handle many other issues, like % in // commands, but in lieu of re-writing the argument parser and command logic completely, I believe this is // a decent stop-gap measure for using " in commands. - defaultUsage = defaultUsage.replaceAll("\"", "\"\""); + defaultUsage = VariableString.quote(defaultUsage); usage = VariableString.newInstance(defaultUsage); assert usage != null; }