fix issue 10405: if the parameter contains Spaces, the invoke telnet command will fail. (#10669)

* fix issue 10405: if the parameter contains Spaces, the invoke telnet command will fail.

* code optimizing.
This commit is contained in:
Wu Daifu 2022-09-26 18:40:05 +08:00 committed by GitHub
parent 2c54859b0b
commit 14fb253f03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 1 deletions

View File

@ -25,11 +25,15 @@ public class TelnetCommandDecoder {
public static final CommandContext decode(String str) {
CommandContext commandContext = null;
if (!StringUtils.isBlank(str)) {
str = str.trim();
String[] array = str.split("(?<![\\\\]) ");
if (array.length > 0) {
String name = array[0];
String[] targetArgs = new String[array.length - 1];
System.arraycopy(array, 1, targetArgs, 0, array.length - 1);
String name = array[0].trim();
if (name.equals("invoke") && array.length > 2) {
targetArgs = reBuildInvokeCmdArgs(str);
}
commandContext = CommandContextFactory.newInstance( name, targetArgs,false);
commandContext.setOriginRequest(str);
}
@ -38,4 +42,8 @@ public class TelnetCommandDecoder {
return commandContext;
}
private static String[] reBuildInvokeCmdArgs(String cmd) {
return new String[] {cmd.substring(cmd.indexOf(" ") + 1).trim()};
}
}