Skip to content

Commit cb3a396

Browse files
committed
Discard quotes for the final execute-able array.
1 parent 1e7352f commit cb3a396

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/mhashim6/commander/main/CommandBuilder.java

+7-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ public class CommandBuilder {
1515
private final ArrayList<String> cmdArgs, cmdOptions, finalCommand;
1616

1717
// private static final String WHITE_SPACE = " ";
18-
private static final String COMMA = ",";
1918
private static final String EMPTY_STRING = "";
2019
private static final Pattern QUOTES_PATTERN = Pattern.compile("([^\"|^']\\S*|[\"|'].+?[\"|'])\\s*");
2120
// ============================================================
@@ -107,9 +106,13 @@ private String finalCmdLine(ArrayList<String> cmdList){
107106
private static String[] splitCmd(String cmd) {
108107
List<String> strings = new ArrayList<>();
109108
Matcher m = QUOTES_PATTERN.matcher(cmd);
110-
while (m.find())
111-
strings.add(m.group(1));
112-
return strings.toArray(new String[strings.size()]);
109+
while (m.find()) {
110+
String token = m.group(1);
111+
token = token.startsWith("'") || token.startsWith("\"") ?
112+
token.replace("'", EMPTY_STRING).replace("\"", EMPTY_STRING) : token;
113+
strings.add(token);
114+
}
115+
return strings.toArray(new String[0]);
113116
}
114117

115118
private void clearAll() {

0 commit comments

Comments
 (0)