1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-02-15 04:32:24 +00:00

Merge pull request #12 from JohnoKing/fix-read-s

`read -S` now correctly handles nested double quotes
This commit is contained in:
Martijn Dekker 2020-06-14 18:50:58 +01:00 committed by GitHub
commit 242d3f768b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 21 additions and 3 deletions

4
NEWS
View file

@ -3,6 +3,10 @@ For full details, see the git log at: https://github.com/ksh93/ksh
Any uppercase BUG_* names are modernish shell bug IDs. Any uppercase BUG_* names are modernish shell bug IDs.
2020-06-14:
- 'read -S' is now able to correctly handle strings with double quotes
nested inside of double quotes.
2020-06-13: 2020-06-13:
- Fixed a timezone name determination bug on FreeBSD that caused the - Fixed a timezone name determination bug on FreeBSD that caused the

View file

@ -566,6 +566,9 @@ int sh_readline(register Shell_t *shp,char **names, volatile int fd, int flags,s
#endif /*SHOPT_MULTIBYTE */ #endif /*SHOPT_MULTIBYTE */
case S_QUOTE: case S_QUOTE:
c = shp->ifstable[*cp++]; c = shp->ifstable[*cp++];
if(inquote && c==S_QUOTE)
c = -1;
else
inquote = !inquote; inquote = !inquote;
if(val) if(val)
{ {
@ -573,6 +576,11 @@ int sh_readline(register Shell_t *shp,char **names, volatile int fd, int flags,s
use_stak = 1; use_stak = 1;
*val = 0; *val = 0;
} }
if(c==-1)
{
stakputc('"');
c = shp->ifstable[*cp++];
}
continue; continue;
case S_ESC: case S_ESC:
/* process escape character */ /* process escape character */

View file

@ -17,4 +17,4 @@
* David Korn <dgk@research.att.com> * * David Korn <dgk@research.att.com> *
* * * *
***********************************************************************/ ***********************************************************************/
#define SH_RELEASE "93u+m 2020-06-11" #define SH_RELEASE "93u+m 2020-06-14"

View file

@ -6679,7 +6679,8 @@ option causes the variable
.I vname\^ .I vname\^
to be read as a compound variable. Blanks will be ignored when to be read as a compound variable. Blanks will be ignored when
finding the beginning open parenthesis. finding the beginning open parenthesis.
The \-S The
.B \-S
option causes the line to be treated like a record in a option causes the line to be treated like a record in a
.B .csv .B .csv
format file so that double quotes can be used to allow the delimiter format file so that double quotes can be used to allow the delimiter

View file

@ -692,5 +692,10 @@ EOF
PATH=/dev/null PATH=/dev/null
whence -q export) || err_exit '`builtin -d` deletes special builtins' whence -q export) || err_exit '`builtin -d` deletes special builtins'
# ======
# `read -S` should handle double quotes correctly
IFS=',' read -S a b c <<<'foo,"""title"" data",bar'
[[ $b == '"title" data' ]] || err_exit '"" inside "" not handled correctly with read -S'
# ====== # ======
exit $((Errors<125?Errors:125)) exit $((Errors<125?Errors:125))