Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

read -S now correctly handles nested double quotes #12

Merged
merged 1 commit into from
Jun 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion src/cmd/ksh93/include/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
* David Korn <dgk@research.att.com> *
* *
***********************************************************************/
#define SH_RELEASE "93u+m 2020-06-11"
#define SH_RELEASE "93u+m 2020-06-14"
3 changes: 2 additions & 1 deletion src/cmd/ksh93/sh.1
Original file line number Diff line number Diff line change
Expand Up @@ -6679,7 +6679,8 @@ option causes the variable
.I vname\^
to be read as a compound variable. Blanks will be ignored when
finding the beginning open parenthesis.
The \-S
The
.B \-S
option causes the line to be treated like a record in a
.B .csv
format file so that double quotes can be used to allow the delimiter
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))