gerrit-sshd: Allow double quoted strings
This provides a facility to nest a single quoted string within another string. Change-Id: Ia7951485836e0e0445dbb0365da3208ae859d739
This commit is contained in:
committed by
Nasser Grainawi
parent
469cf9a662
commit
80de50cab1
@@ -168,21 +168,31 @@ class CommandFactoryProvider implements Provider<CommandFactory> {
|
|||||||
static String[] split(String commandLine) {
|
static String[] split(String commandLine) {
|
||||||
final List<String> list = new ArrayList<String>();
|
final List<String> list = new ArrayList<String>();
|
||||||
boolean inquote = false;
|
boolean inquote = false;
|
||||||
|
boolean inDblQuote = false;
|
||||||
StringBuilder r = new StringBuilder();
|
StringBuilder r = new StringBuilder();
|
||||||
for (int ip = 0; ip < commandLine.length();) {
|
for (int ip = 0; ip < commandLine.length();) {
|
||||||
final char b = commandLine.charAt(ip++);
|
final char b = commandLine.charAt(ip++);
|
||||||
switch (b) {
|
switch (b) {
|
||||||
case '\t':
|
case '\t':
|
||||||
case ' ':
|
case ' ':
|
||||||
if (inquote)
|
if (inquote || inDblQuote)
|
||||||
r.append(b);
|
r.append(b);
|
||||||
else if (r.length() > 0) {
|
else if (r.length() > 0) {
|
||||||
list.add(r.toString());
|
list.add(r.toString());
|
||||||
r = new StringBuilder();
|
r = new StringBuilder();
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
|
case '\"':
|
||||||
|
if (inquote)
|
||||||
|
r.append(b);
|
||||||
|
else
|
||||||
|
inDblQuote = !inDblQuote;
|
||||||
|
continue;
|
||||||
case '\'':
|
case '\'':
|
||||||
inquote = !inquote;
|
if (inDblQuote)
|
||||||
|
r.append(b);
|
||||||
|
else
|
||||||
|
inquote = !inquote;
|
||||||
continue;
|
continue;
|
||||||
case '\\':
|
case '\\':
|
||||||
if (inquote || ip == commandLine.length())
|
if (inquote || ip == commandLine.length())
|
||||||
|
|||||||
Reference in New Issue
Block a user