1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

Fix 'read -a' failure to create array (re: d55e9686) (#516)

The commit that backported read -a did not add a case label for it
to read.c. This was under the assumption that AST optget(3) would
always convert -a to -A. However, that was only done for first use.

The cause is the short-form options caching mechanism in optget(3).
On the first run, the pre-caching result would be returned, but the
equivalent option (-a) would be cached as if it is its own option,
so on the second and subsequent runs, optget returned 'a' instead
of 'A'. This only happens if no long-form equivalent is present.

Reproducer:

  $ read -A foo <<< 'foo bar baz'
  $ unset foo
  $ read -a foo <<< 'foo bar baz'
  $ echo ${foo[0]}
  foo bar baz

Expected: foo

src/lib/libast/misc/optget.c,
src/lib/libast/misc/optlib.h:
- [by Martijn Dekker] Implement caching for short-option
  equivalents. If a short-form equivalent is found, instead of
  caching it as a separate option, cache the equivalent in a new
  equiv[] array. Check this when reading the cache and substitute
  the main option for the equivalent if one is cached.

src/lib/libcmd/cp.c:
- Fix cp -r/cp -R symlink handling. The -r and -R options sometimes
  ignored -P, -L and -H.
- The -r and -R options no longer follow symlinks by default.

src/cmd/ksh93/bltins/whence.c,
src/lib/libcmd/*.c:
- Remove case labels that are redundant now that the optget(3)
  caching bug is fixed.

src/cmd/ksh93/tests/libcmd.sh:
- Added. This is the new script for the /opt/ast/bin path-bound
  built-ins from libcmd. Other relevant tests are moved into here.

Co-authored-by: Martijn Dekker <martijn@inlv.org>
This commit is contained in:
Johnothan King 2022-08-20 09:10:17 -07:00 committed by Martijn Dekker
parent aa1f8244e6
commit bea4fd56e8
12 changed files with 400 additions and 210 deletions

10
NEWS
View file

@ -2,6 +2,16 @@ This documents significant changes in the 1.0 branch of ksh 93u+m.
For full details, see the git log at: https://github.com/ksh93/ksh/tree/1.0
Uppercase BUG_* IDs are shell bug IDs as used by the Modernish shell library.
2022-08-20:
- Fixed a bug in command line options processing that caused short-form
option equivalents on some built-in commands to be ignored after one use,
e.g., the new read -a equivalent of read -A (introduced on 2022-02-16).
- Fixed a bug in the /opt/ast/bin/cp built-in command that caused the -r and
-R options to sometimes ignore -P, -L and -H. Additionally, the -r and -R
options no longer follow symlinks by default.
2022-08-16:
- Fixed an old bug in history expansion (set -H) where any use of the history