fix IFS='\' issues, found by edualbus (Eduardo A. Bustamante López <dualbus@gmail.com>)
This commit is contained in:
62
check.t
62
check.t
@ -1,4 +1,4 @@
|
|||||||
# $MirOS: src/bin/mksh/check.t,v 1.687 2015/03/20 23:37:52 tg Exp $
|
# $MirOS: src/bin/mksh/check.t,v 1.688 2015/04/11 21:18:45 tg Exp $
|
||||||
# -*- mode: sh -*-
|
# -*- mode: sh -*-
|
||||||
#-
|
#-
|
||||||
# Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
|
# Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
|
||||||
@ -4842,6 +4842,66 @@ expected-stdout:
|
|||||||
1a:
|
1a:
|
||||||
2: x[A B]
|
2: x[A B]
|
||||||
---
|
---
|
||||||
|
name: read-IFS-2
|
||||||
|
description:
|
||||||
|
Complex tests, IFS either colon (IFS-NWS) or backslash (tricky)
|
||||||
|
stdin:
|
||||||
|
n=0
|
||||||
|
showargs() { print -nr "$1"; shift; for s_arg in "$@"; do print -nr -- " [$s_arg]"; done; print; }
|
||||||
|
(IFS=\\ a=\<\\\>; showargs 3 $a)
|
||||||
|
(IFS=: b=\<:\>; showargs 4 $b)
|
||||||
|
print -r '<\>' | (IFS=\\ read f g; showargs 5 "$f" "$g")
|
||||||
|
print -r '<\\>' | (IFS=\\ read f g; showargs 6 "$f" "$g")
|
||||||
|
print '<\\\n>' | (IFS=\\ read f g; showargs 7 "$f" "$g")
|
||||||
|
print -r '<\>' | (IFS=\\ read f; showargs 8 "$f")
|
||||||
|
print -r '<\\>' | (IFS=\\ read f; showargs 9 "$f")
|
||||||
|
print '<\\\n>' | (IFS=\\ read f; showargs 10 "$f")
|
||||||
|
print -r '<\>' | (IFS=\\ read -r f g; showargs 11 "$f" "$g")
|
||||||
|
print -r '<\\>' | (IFS=\\ read -r f g; showargs 12 "$f" "$g")
|
||||||
|
print '<\\\n>' | (IFS=\\ read -r f g; showargs 13 "$f" "$g")
|
||||||
|
print -r '<\>' | (IFS=\\ read -r f; showargs 14 "$f")
|
||||||
|
print -r '<\\>' | (IFS=\\ read -r f; showargs 15 "$f")
|
||||||
|
print '<\\\n>' | (IFS=\\ read -r f; showargs 16 "$f")
|
||||||
|
print -r '<:>' | (IFS=: read f g; showargs 17 "$f" "$g")
|
||||||
|
print -r '<::>' | (IFS=: read f g; showargs 18 "$f" "$g")
|
||||||
|
print '<:\n>' | (IFS=: read f g; showargs 19 "$f" "$g")
|
||||||
|
print -r '<:>' | (IFS=: read f; showargs 20 "$f")
|
||||||
|
print -r '<::>' | (IFS=: read f; showargs 21 "$f")
|
||||||
|
print '<:\n>' | (IFS=: read f; showargs 22 "$f")
|
||||||
|
print -r '<:>' | (IFS=: read -r f g; showargs 23 "$f" "$g")
|
||||||
|
print -r '<::>' | (IFS=: read -r f g; showargs 24 "$f" "$g")
|
||||||
|
print '<:\n>' | (IFS=: read -r f g; showargs 25 "$f" "$g")
|
||||||
|
print -r '<:>' | (IFS=: read -r f; showargs 26 "$f")
|
||||||
|
print -r '<::>' | (IFS=: read -r f; showargs 27 "$f")
|
||||||
|
print '<:\n>' | (IFS=: read -r f; showargs 28 "$f")
|
||||||
|
expected-stdout:
|
||||||
|
3 [<] [>]
|
||||||
|
4 [<] [>]
|
||||||
|
5 [<] [>]
|
||||||
|
6 [<] [>]
|
||||||
|
7 [<>] []
|
||||||
|
8 [<>]
|
||||||
|
9 [<\>]
|
||||||
|
10 [<>]
|
||||||
|
11 [<] [>]
|
||||||
|
12 [<] [\>]
|
||||||
|
13 [<] []
|
||||||
|
14 [<\>]
|
||||||
|
15 [<\\>]
|
||||||
|
16 [<]
|
||||||
|
17 [<] [>]
|
||||||
|
18 [<] [:>]
|
||||||
|
19 [<] []
|
||||||
|
20 [<:>]
|
||||||
|
21 [<::>]
|
||||||
|
22 [<]
|
||||||
|
23 [<] [>]
|
||||||
|
24 [<] [:>]
|
||||||
|
25 [<] []
|
||||||
|
26 [<:>]
|
||||||
|
27 [<::>]
|
||||||
|
28 [<]
|
||||||
|
---
|
||||||
name: read-ksh-1
|
name: read-ksh-1
|
||||||
description:
|
description:
|
||||||
If no var specified, REPLY is used
|
If no var specified, REPLY is used
|
||||||
|
20
funcs.c
20
funcs.c
@ -38,7 +38,7 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.266 2015/03/20 21:01:41 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.267 2015/04/11 21:18:47 tg Exp $");
|
||||||
|
|
||||||
#if HAVE_KILLPG
|
#if HAVE_KILLPG
|
||||||
/*
|
/*
|
||||||
@ -1821,9 +1821,10 @@ int
|
|||||||
c_read(const char **wp)
|
c_read(const char **wp)
|
||||||
{
|
{
|
||||||
#define is_ifsws(c) (ctype((c), C_IFS) && ctype((c), C_IFSWS))
|
#define is_ifsws(c) (ctype((c), C_IFS) && ctype((c), C_IFSWS))
|
||||||
int c, fd = 0, rv = 0, lastparm = 0;
|
int c, fd = 0, rv = 0;
|
||||||
bool savehist = false, intoarray = false, aschars = false;
|
bool savehist = false, intoarray = false, aschars = false;
|
||||||
bool rawmode = false, expanding = false;
|
bool rawmode = false, expanding = false;
|
||||||
|
bool lastparmmode = false, lastparmused = false;
|
||||||
enum { LINES, BYTES, UPTO, READALL } readmode = LINES;
|
enum { LINES, BYTES, UPTO, READALL } readmode = LINES;
|
||||||
char delim = '\n';
|
char delim = '\n';
|
||||||
size_t bytesleft = 128, bytesread;
|
size_t bytesleft = 128, bytesread;
|
||||||
@ -2127,7 +2128,7 @@ c_read(const char **wp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!intoarray && wp[1] == NULL)
|
if (!intoarray && wp[1] == NULL)
|
||||||
lastparm = 1;
|
lastparmmode = true;
|
||||||
|
|
||||||
c_read_splitlast:
|
c_read_splitlast:
|
||||||
/* copy until IFS character */
|
/* copy until IFS character */
|
||||||
@ -2152,16 +2153,23 @@ c_read(const char **wp)
|
|||||||
}
|
}
|
||||||
xsave = Xsavepos(xs, xp);
|
xsave = Xsavepos(xs, xp);
|
||||||
/* copy word delimiter: IFSWS+IFS,IFSWS */
|
/* copy word delimiter: IFSWS+IFS,IFSWS */
|
||||||
|
expanding = false;
|
||||||
while (bytesread) {
|
while (bytesread) {
|
||||||
char ch;
|
char ch;
|
||||||
|
|
||||||
ch = *ccp;
|
ch = *ccp;
|
||||||
if (!ctype(ch, C_IFS))
|
if (!ctype(ch, C_IFS))
|
||||||
break;
|
break;
|
||||||
|
if (lastparmmode && !expanding && !rawmode && ch == '\\') {
|
||||||
|
expanding = true;
|
||||||
|
} else {
|
||||||
Xcheck(xs, xp);
|
Xcheck(xs, xp);
|
||||||
Xput(xs, xp, ch);
|
Xput(xs, xp, ch);
|
||||||
|
}
|
||||||
++ccp;
|
++ccp;
|
||||||
--bytesread;
|
--bytesread;
|
||||||
|
if (expanding)
|
||||||
|
continue;
|
||||||
if (!ctype(ch, C_IFSWS))
|
if (!ctype(ch, C_IFSWS))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -2172,12 +2180,12 @@ c_read(const char **wp)
|
|||||||
--bytesread;
|
--bytesread;
|
||||||
}
|
}
|
||||||
/* if no more parameters, rinse and repeat */
|
/* if no more parameters, rinse and repeat */
|
||||||
if (lastparm && bytesread) {
|
if (lastparmmode && bytesread) {
|
||||||
++lastparm;
|
lastparmused = true;
|
||||||
goto c_read_splitlast;
|
goto c_read_splitlast;
|
||||||
}
|
}
|
||||||
/* get rid of the delimiter unless we pack the rest */
|
/* get rid of the delimiter unless we pack the rest */
|
||||||
if (lastparm < 2)
|
if (!lastparmused)
|
||||||
xp = Xrestpos(xs, xp, xsave);
|
xp = Xrestpos(xs, xp, xsave);
|
||||||
c_read_gotword:
|
c_read_gotword:
|
||||||
Xput(xs, xp, '\0');
|
Xput(xs, xp, '\0');
|
||||||
|
Reference in New Issue
Block a user