From 3fce00cb4bc5bba47ae8c0e48d74a5a35f0eea43 Mon Sep 17 00:00:00 2001 From: NewbieOrange Date: Tue, 14 Sep 2021 00:37:05 +0800 Subject: [PATCH] Fix logical fault of possibly replacing other command names --- src/main/java/picocli/AutoComplete.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/picocli/AutoComplete.java b/src/main/java/picocli/AutoComplete.java index 6c183c235..a2d22703c 100644 --- a/src/main/java/picocli/AutoComplete.java +++ b/src/main/java/picocli/AutoComplete.java @@ -560,7 +560,8 @@ private static void generateFunctionCallsToArrContains(StringBuilder buff, int count = functionCalls.size(); CommandSpec spec = descriptor.commandLine.getCommandSpec(); String full = spec.qualifiedName(" "); - String withoutTopLevelCommand = full.substring(spec.root().name().length() + 1).replace(spec.name(), descriptor.commandName); + String withoutTopLevelCommand = full.substring(spec.root().name().length() + 1, + full.length() - spec.name().length()) + descriptor.commandName; functionCalls.add(format(" if CompWordsContainsArray \"${cmds%2$d[@]}\"; then %1$s; return $?; fi\n", descriptor.functionName, count)); buff.append( format(" local cmds%2$d=(%1$s)\n", withoutTopLevelCommand, count));