Skip to content

Commit

Permalink
read -S now correctly handles nested double quotes
Browse files Browse the repository at this point in the history
Prior to this bugfix, the following set of commands would
fail to print two double quotes:

IFS=',' read -S a b c <<<'foo,"""title"" data",bar'
echo $b

This fix is from ksh93v- 2013-10-10-alpha, although it has
been revised to use stakputc to put the required double quote
into the buffer for consistency with the ksh93u+ codebase.

src/cmd/ksh93/bltins/read.c:
 - When handling nested double quotes, put the required double
   quote in read's buffer with stakputc.

src/cmd/ksh93/tests/builtins.sh:
 - Add the regression test for `read -S` from ksh93v-.
  • Loading branch information
JohnoKing committed Jun 14, 2020
1 parent 5498d9e commit 5eef7dd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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.

2020-06-14:
- 'read -S' is now able to correctly handle strings with double quotes
nested inside of double quotes.

2020-06-13:

- Fixed a timezone name determination bug on FreeBSD that caused the
Expand Down
10 changes: 9 additions & 1 deletion src/cmd/ksh93/bltins/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -566,13 +566,21 @@ int sh_readline(register Shell_t *shp,char **names, volatile int fd, int flags,s
#endif /*SHOPT_MULTIBYTE */
case S_QUOTE:
c = shp->ifstable[*cp++];
inquote = !inquote;
if(inquote && c==S_QUOTE)
c = -1;
else
inquote = !inquote;
if(val)
{
stakputs(val);
use_stak = 1;
*val = 0;
}
if(c==-1)
{
stakputc('"');
c = shp->ifstable[*cp++];
}
continue;
case S_ESC:
/* process escape character */
Expand Down
5 changes: 5 additions & 0 deletions src/cmd/ksh93/tests/builtins.sh
Original file line number Diff line number Diff line change
Expand Up @@ -692,5 +692,10 @@ EOF
PATH=/dev/null
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))

0 comments on commit 5eef7dd

Please sign in to comment.