mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-04 07:53:50 +00:00
virsh: better support double quote
In origin code, double quote is only allowed at the begin or end "complicated argument" --some_opt="complicated string" (we split this argument into 2 parts, option and data, the data is "complicated string"). This patch makes it allow double quote at any position of an argument: complicated" argument" complicated" "argument --"some opt=complicated string" This patch is also needed for the following patches, the following patches will not split option argument into 2 parts, so we have to allow double quote at any position of an argument. Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
This commit is contained in:
parent
94f232bb9b
commit
ad2f1b6093
1
AUTHORS
1
AUTHORS
@ -130,6 +130,7 @@ Patches have also been contributed by:
|
|||||||
Patrick Dignan <pat_dignan@dell.com>
|
Patrick Dignan <pat_dignan@dell.com>
|
||||||
Serge Hallyn <serge.hallyn@canonical.com>
|
Serge Hallyn <serge.hallyn@canonical.com>
|
||||||
Nikunj A. Dadhania <nikunj@linux.vnet.ibm.com>
|
Nikunj A. Dadhania <nikunj@linux.vnet.ibm.com>
|
||||||
|
Lai Jiangshan <laijs@cn.fujitsu.com>
|
||||||
|
|
||||||
[....send patches to get your name here....]
|
[....send patches to get your name here....]
|
||||||
|
|
||||||
|
@ -10271,16 +10271,18 @@ vshCommandRun(vshControl *ctl, const vshCmd *cmd)
|
|||||||
#define VSH_TK_DATA 2
|
#define VSH_TK_DATA 2
|
||||||
#define VSH_TK_END 3
|
#define VSH_TK_END 3
|
||||||
|
|
||||||
static int
|
static int ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4)
|
||||||
vshCommandGetToken(vshControl *ctl, char *str, char **end, char **res)
|
vshCommandGetToken(vshControl *ctl, char *str, char **end, char **res)
|
||||||
{
|
{
|
||||||
int tk = VSH_TK_NONE;
|
int tk = VSH_TK_NONE;
|
||||||
int quote = FALSE;
|
bool double_quote = false;
|
||||||
int sz = 0;
|
int sz = 0;
|
||||||
char *p = str;
|
char *p = str;
|
||||||
|
char *q = vshStrdup(ctl, str);
|
||||||
char *tkstr = NULL;
|
char *tkstr = NULL;
|
||||||
|
|
||||||
*end = NULL;
|
*end = NULL;
|
||||||
|
*res = q;
|
||||||
|
|
||||||
while (p && *p && (*p == ' ' || *p == '\t'))
|
while (p && *p && (*p == ' ' || *p == '\t'))
|
||||||
p++;
|
p++;
|
||||||
@ -10291,9 +10293,10 @@ vshCommandGetToken(vshControl *ctl, char *str, char **end, char **res)
|
|||||||
*end = ++p; /* = \0 or begin of next command */
|
*end = ++p; /* = \0 or begin of next command */
|
||||||
return VSH_TK_END;
|
return VSH_TK_END;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (*p) {
|
while (*p) {
|
||||||
/* end of token is blank space or ';' */
|
/* end of token is blank space or ';' */
|
||||||
if ((quote == FALSE && (*p == ' ' || *p == '\t')) || *p == ';')
|
if (!double_quote && (*p == ' ' || *p == '\t' || *p == ';'))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* end of option name could be '=' */
|
/* end of option name could be '=' */
|
||||||
@ -10309,35 +10312,27 @@ vshCommandGetToken(vshControl *ctl, char *str, char **end, char **res)
|
|||||||
p += 2;
|
p += 2;
|
||||||
} else {
|
} else {
|
||||||
tk = VSH_TK_DATA;
|
tk = VSH_TK_DATA;
|
||||||
if (*p == '"') {
|
|
||||||
quote = TRUE;
|
|
||||||
p++;
|
|
||||||
} else {
|
|
||||||
quote = FALSE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
tkstr = p; /* begin of token */
|
tkstr = p; /* begin of token */
|
||||||
} else if (quote && *p == '"') {
|
|
||||||
quote = FALSE;
|
|
||||||
p++;
|
|
||||||
break; /* end of "..." token */
|
|
||||||
}
|
}
|
||||||
p++;
|
|
||||||
|
if (*p == '"') {
|
||||||
|
double_quote = !double_quote;
|
||||||
|
p++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
*q++ = *p++;
|
||||||
sz++;
|
sz++;
|
||||||
}
|
}
|
||||||
if (quote) {
|
if (double_quote) {
|
||||||
vshError(ctl, "%s", _("missing \""));
|
vshError(ctl, "%s", _("missing \""));
|
||||||
return VSH_TK_ERROR;
|
return VSH_TK_ERROR;
|
||||||
}
|
}
|
||||||
if (tkstr == NULL || *tkstr == '\0' || p == NULL)
|
if (tkstr == NULL || *tkstr == '\0' || sz == 0)
|
||||||
return VSH_TK_END;
|
|
||||||
if (sz == 0)
|
|
||||||
return VSH_TK_END;
|
return VSH_TK_END;
|
||||||
|
|
||||||
*res = vshMalloc(ctl, sz + 1);
|
*q = '\0';
|
||||||
memcpy(*res, tkstr, sz);
|
|
||||||
*(*res + sz) = '\0';
|
|
||||||
|
|
||||||
*end = p;
|
*end = p;
|
||||||
return tk;
|
return tk;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user