mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-09-17 15:01:40 +02:00
fix for unquoting with `compset -q' with singly and doubly quoted strings (17135)
This commit is contained in:
parent
876becb49a
commit
0cfe1b30be
3 changed files with 106 additions and 16 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
2002-05-13 Sven Wischnowsky <wischnow@zsh.org>
|
||||||
|
|
||||||
|
* 17135: Src/Zle/compcore.c, Src/Zle/zle_tricky.c: fix for
|
||||||
|
unquoting with `compset -q' with singly and doubly quoted
|
||||||
|
strings
|
||||||
|
|
||||||
2002-05-12 Peter Stephenson <pws@pwstephenson.fsnet.co.uk>
|
2002-05-12 Peter Stephenson <pws@pwstephenson.fsnet.co.uk>
|
||||||
|
|
||||||
* c.f. 17128: Doc/Makefile.in: back out changes accidentally
|
* c.f. 17128: Doc/Makefile.in: back out changes accidentally
|
||||||
|
|
|
@ -1175,6 +1175,30 @@ rembslash(char *s)
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Remove one of every pair of single quotes, without copying. Return
|
||||||
|
* the number of removed quotes. */
|
||||||
|
|
||||||
|
/**/
|
||||||
|
mod_export int
|
||||||
|
remsquote(char *s)
|
||||||
|
{
|
||||||
|
int ret = 0, qa = (isset(RCQUOTES) ? 1 : 3);
|
||||||
|
char *t = s;
|
||||||
|
|
||||||
|
while (*s)
|
||||||
|
if (qa == 1 ?
|
||||||
|
(s[0] == '\'' && s[1] == '\'') :
|
||||||
|
(s[0] == '\'' && s[1] == '\\' && s[2] == '\'' && s[3] == '\'')) {
|
||||||
|
ret += qa;
|
||||||
|
*t++ = '\'';
|
||||||
|
s += qa + 1;
|
||||||
|
} else
|
||||||
|
*t++ = *s++;
|
||||||
|
*t = '\0';
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
/* This should probably be moved into tokenize(). */
|
/* This should probably be moved into tokenize(). */
|
||||||
|
|
||||||
/**/
|
/**/
|
||||||
|
@ -1244,7 +1268,8 @@ set_comp_sep(void)
|
||||||
LinkList foo = newlinklist();
|
LinkList foo = newlinklist();
|
||||||
LinkNode n;
|
LinkNode n;
|
||||||
int owe = we, owb = wb, ocs = cs, swb, swe, scs, soffs, ne = noerrs;
|
int owe = we, owb = wb, ocs = cs, swb, swe, scs, soffs, ne = noerrs;
|
||||||
int tl, got = 0, i = 0, cur = -1, oll = ll, sl, remq;
|
int tl, got = 0, i = 0, j, cur = -1, oll = ll, sl;
|
||||||
|
int remq = 0, dq = 0, odq, sq = 0, osq, issq = 0, sqq = 0, lsq = 0, qa = 0;
|
||||||
int ois = instring, oib = inbackt, noffs = lp, ona = noaliases;
|
int ois = instring, oib = inbackt, noffs = lp, ona = noaliases;
|
||||||
char *tmp, *p, *ns, *ol = (char *) line, sav, *qp, *qs, *ts, qc = '\0';
|
char *tmp, *p, *ns, *ol = (char *) line, sav, *qp, *qs, *ts, qc = '\0';
|
||||||
|
|
||||||
|
@ -1266,8 +1291,33 @@ set_comp_sep(void)
|
||||||
memcpy(tmp + 1, s, noffs);
|
memcpy(tmp + 1, s, noffs);
|
||||||
tmp[(scs = cs = 1 + noffs)] = 'x';
|
tmp[(scs = cs = 1 + noffs)] = 'x';
|
||||||
strcpy(tmp + 2 + noffs, s + noffs);
|
strcpy(tmp + 2 + noffs, s + noffs);
|
||||||
if ((remq = (*compqstack == '\\')))
|
|
||||||
|
switch (*compqstack) {
|
||||||
|
case '\\':
|
||||||
|
remq = 1;
|
||||||
tmp = rembslash(tmp);
|
tmp = rembslash(tmp);
|
||||||
|
break;
|
||||||
|
case '\'':
|
||||||
|
issq = 1;
|
||||||
|
if (isset(RCQUOTES))
|
||||||
|
qa = 1;
|
||||||
|
else
|
||||||
|
qa = 3;
|
||||||
|
|
||||||
|
sq = remsquote(tmp);
|
||||||
|
|
||||||
|
break;
|
||||||
|
case '"':
|
||||||
|
for (j = 0, p = tmp; *p; p++, j++)
|
||||||
|
if (*p == '\\' && p[1] == '\\') {
|
||||||
|
dq++;
|
||||||
|
chuck(p);
|
||||||
|
if (!*p)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
odq = dq;
|
||||||
|
osq = sq;
|
||||||
inpush(dupstrspace(tmp), 0, NULL);
|
inpush(dupstrspace(tmp), 0, NULL);
|
||||||
line = (unsigned char *) tmp;
|
line = (unsigned char *) tmp;
|
||||||
ll = tl - 1;
|
ll = tl - 1;
|
||||||
|
@ -1280,9 +1330,10 @@ set_comp_sep(void)
|
||||||
|
|
||||||
if (!tokstr)
|
if (!tokstr)
|
||||||
break;
|
break;
|
||||||
for (j = 0, p = tokstr; *p; p++)
|
for (j = 0, p = tokstr; *p; p++) {
|
||||||
if (*p == Snull || *p == Dnull)
|
if (*p == Snull || *p == Dnull)
|
||||||
j++;
|
j++;
|
||||||
|
}
|
||||||
if (j & 1) {
|
if (j & 1) {
|
||||||
tok = STRING;
|
tok = STRING;
|
||||||
if (p > tokstr && p[-1] == ' ')
|
if (p > tokstr && p[-1] == ' ')
|
||||||
|
@ -1291,16 +1342,33 @@ set_comp_sep(void)
|
||||||
}
|
}
|
||||||
if (tok == ENDINPUT || tok == LEXERR)
|
if (tok == ENDINPUT || tok == LEXERR)
|
||||||
break;
|
break;
|
||||||
if (tokstr && *tokstr)
|
if (tokstr && *tokstr) {
|
||||||
|
for (p = tokstr; dq && *p; p++)
|
||||||
|
if (*p == Bnull)
|
||||||
|
dq--;
|
||||||
|
if (issq) {
|
||||||
|
for (p = tokstr, lsq = 0; *p; p++) {
|
||||||
|
if (sq && *p == Snull)
|
||||||
|
sq -= qa;
|
||||||
|
if (*p == '\'') {
|
||||||
|
sq -= qa;
|
||||||
|
lsq += qa;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
lsq = 0;
|
||||||
addlinknode(foo, (p = ztrdup(tokstr)));
|
addlinknode(foo, (p = ztrdup(tokstr)));
|
||||||
|
}
|
||||||
else
|
else
|
||||||
p = NULL;
|
p = NULL;
|
||||||
if (!got && !zleparse) {
|
if (!got && !zleparse) {
|
||||||
DPUTS(!p, "no current word in substr");
|
DPUTS(!p, "no current word in substr");
|
||||||
got = 1;
|
got = 1;
|
||||||
cur = i;
|
cur = i;
|
||||||
swb = wb - 1;
|
swb = wb - 1 - dq - sq;
|
||||||
swe = we - 1;
|
swe = we - 1 - dq - sq;
|
||||||
|
sqq = lsq;
|
||||||
soffs = cs - swb;
|
soffs = cs - swb;
|
||||||
chuck(p + soffs);
|
chuck(p + soffs);
|
||||||
ns = dupstring(p);
|
ns = dupstring(p);
|
||||||
|
@ -1352,8 +1420,12 @@ set_comp_sep(void)
|
||||||
for (p = ns, i = swb; *p; p++, i++) {
|
for (p = ns, i = swb; *p; p++, i++) {
|
||||||
if (INULL(*p)) {
|
if (INULL(*p)) {
|
||||||
if (i < scs) {
|
if (i < scs) {
|
||||||
if (remq && *p == Bnull && p[1])
|
if (*p == Bnull && p[1]) {
|
||||||
swb -= 2;
|
if (remq)
|
||||||
|
swb -= 2;
|
||||||
|
if (odq)
|
||||||
|
swb--;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (p[1] || *p != Bnull) {
|
if (p[1] || *p != Bnull) {
|
||||||
if (*p == Bnull) {
|
if (*p == Bnull) {
|
||||||
|
@ -1378,9 +1450,9 @@ set_comp_sep(void)
|
||||||
if (ql > rl)
|
if (ql > rl)
|
||||||
swb -= ql - rl;
|
swb -= ql - rl;
|
||||||
}
|
}
|
||||||
sav = s[(i = swb - 1)];
|
sav = s[(i = swb - 1 - sqq)];
|
||||||
s[i] = '\0';
|
s[i] = '\0';
|
||||||
qp = rembslash(s);
|
qp = (issq ? dupstring(s) : rembslash(s));
|
||||||
s[i] = sav;
|
s[i] = sav;
|
||||||
if (swe < swb)
|
if (swe < swb)
|
||||||
swe = swb;
|
swe = swb;
|
||||||
|
@ -1391,11 +1463,14 @@ set_comp_sep(void)
|
||||||
if (strlen(ns) > swe - swb + 1)
|
if (strlen(ns) > swe - swb + 1)
|
||||||
ns[swe - swb + 1] = '\0';
|
ns[swe - swb + 1] = '\0';
|
||||||
}
|
}
|
||||||
qs = rembslash(s + swe);
|
qs = (issq ? dupstring(s + swe) : rembslash(s + swe));
|
||||||
sl = strlen(ns);
|
sl = strlen(ns);
|
||||||
if (soffs > sl)
|
if (soffs > sl)
|
||||||
soffs = sl;
|
soffs = sl;
|
||||||
|
if (issq) {
|
||||||
|
remsquote(qp);
|
||||||
|
remsquote(qs);
|
||||||
|
}
|
||||||
{
|
{
|
||||||
int set = CP_QUOTE | CP_QUOTING, unset = 0;
|
int set = CP_QUOTE | CP_QUOTING, unset = 0;
|
||||||
|
|
||||||
|
|
|
@ -985,7 +985,7 @@ static char *
|
||||||
get_comp_string(void)
|
get_comp_string(void)
|
||||||
{
|
{
|
||||||
int t0, tt0, i, j, k, cp, rd, sl, ocs, ins, oins, ia, parct, varq = 0;
|
int t0, tt0, i, j, k, cp, rd, sl, ocs, ins, oins, ia, parct, varq = 0;
|
||||||
int ona = noaliases;
|
int ona = noaliases, qsub;
|
||||||
char *s = NULL, *linptr, *tmp, *p, *tt = NULL, rdop[20];
|
char *s = NULL, *linptr, *tmp, *p, *tt = NULL, rdop[20];
|
||||||
|
|
||||||
freebrinfo(brbeg);
|
freebrinfo(brbeg);
|
||||||
|
@ -1051,6 +1051,8 @@ get_comp_string(void)
|
||||||
* and whatnot. */
|
* and whatnot. */
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
qsub = 0;
|
||||||
|
|
||||||
lincmd = ((incmdpos && !ins && !incond) || (oins == 2 && i == 2) ||
|
lincmd = ((incmdpos && !ins && !incond) || (oins == 2 && i == 2) ||
|
||||||
(ins == 3 && i == 1));
|
(ins == 3 && i == 1));
|
||||||
linredir = (inredir && !ins);
|
linredir = (inredir && !ins);
|
||||||
|
@ -1126,9 +1128,16 @@ get_comp_string(void)
|
||||||
if (!zleparse && !tt0) {
|
if (!zleparse && !tt0) {
|
||||||
/* This is done when the lexer reached the word the cursor is on. */
|
/* This is done when the lexer reached the word the cursor is on. */
|
||||||
tt = tokstr ? dupstring(tokstr) : NULL;
|
tt = tokstr ? dupstring(tokstr) : NULL;
|
||||||
|
|
||||||
|
if (isset(RCQUOTES) && *tt == Snull) {
|
||||||
|
char *p, *e = tt + cs - wb;
|
||||||
|
for (p = tt; *p && p < e; p++)
|
||||||
|
if (*p == '\'')
|
||||||
|
qsub++;
|
||||||
|
}
|
||||||
/* If we added a `x', remove it. */
|
/* If we added a `x', remove it. */
|
||||||
if (addedx && tt)
|
if (addedx && tt)
|
||||||
chuck(tt + cs - wb);
|
chuck(tt + cs - wb - qsub);
|
||||||
tt0 = tok;
|
tt0 = tok;
|
||||||
/* Store the number of this word. */
|
/* Store the number of this word. */
|
||||||
clwpos = i;
|
clwpos = i;
|
||||||
|
@ -1176,8 +1185,8 @@ get_comp_string(void)
|
||||||
/* If this is the word the cursor is in and we added a `x', *
|
/* If this is the word the cursor is in and we added a `x', *
|
||||||
* remove it. */
|
* remove it. */
|
||||||
if (clwpos == i++ && addedx)
|
if (clwpos == i++ && addedx)
|
||||||
chuck(&clwords[i - 1][((cs - wb) >= sl) ?
|
chuck(&clwords[i - 1][((cs - wb - qsub) >= sl) ?
|
||||||
(sl - 1) : (cs - wb)]);
|
(sl - 1) : (cs - wb - qsub)]);
|
||||||
} while (tok != LEXERR && tok != ENDINPUT &&
|
} while (tok != LEXERR && tok != ENDINPUT &&
|
||||||
(tok != SEPER || (zleparse && !tt0)));
|
(tok != SEPER || (zleparse && !tt0)));
|
||||||
/* Calculate the number of words stored in the clwords array. */
|
/* Calculate the number of words stored in the clwords array. */
|
||||||
|
|
Loading…
Reference in a new issue