1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00
cde/src/cmd/ksh93/include
Martijn Dekker dde8da6769 Fix history comment character in history expansion (re: 41ee12a5)
Reproducer: on an interactive shell with the -H option on,

  $ v=foo
  $ print ${#v}

does not print anything (but should print "3").
The 'print' line also is not added to the history.

This bug was exposed by commit 41ee12a5 which enabled the history
comment character by default, setting it to '#' as on bash. When it
was disabled by default, this bug was rarely exposed.

The problem happens here:

src/cmd/ksh93/edit/hexpand.c
203: if(hc[2] && *cp == hc[2]) /* history comment designator, skip rest of line */
204: {
205: 	stakputc(*cp++);
206: 	stakputs(cp);
207: 	DONE();
208: }

The DONE() macro sets the HIST_ERROR bit flag:

src/cmd/ksh93/edit/hexpand.c
45: #define	DONE()	{flag |= HIST_ERROR; cp = 0; stakseek(0); goto done;}

For the history comment character that is clearly wrong, as no
error has occurred.

There is another problem. The documentation I added for history
expansion states this bit, which is based on bash's behaviour:

    If a word on a command line begins with the history comment
    character #, history expansion is ignored for the rest of that
    line.

With an expansion like ${#v}, the word does not begin with # so
history expansion should not have parsed that as a comment
character. The intention was to act like bash.

src/cmd/ksh93/edit/hexpand.c:
- Split the DONE() macro into DONE and ERROROUT of which only the
  latter sets the HIST_ERROR bit flag. Change usage accordingly.
  Thix fixes the first problem.
- Don't make these new macros function-style macros (with ()) as
  they end in a goto, so that's a bit misleading.
- Add is_wordboundary() which makes a best-effort attempt to
  determine if the character following the specified character is
  considered to start a new word by shell grammar rules. Word
  boundary characters are whitespace and: |&;()`<>
- Only recognise the history comment character if is_wordbounary()
  returns true for the previous character. This fixes the second
  problem.

Thanks to @jghub for the bug report.
Resolves: https://github.com/ksh93/ksh/issues/513
2022-08-16 22:00:20 +01:00
..
argnod.h Update author attributions in all source files 2022-07-31 00:47:08 +02:00
builtins.h Update author attributions in all source files 2022-07-31 00:47:08 +02:00
defs.h Update author attributions in all source files 2022-07-31 00:47:08 +02:00
edit.h Update author attributions in all source files 2022-07-31 00:47:08 +02:00
fault.h Update author attributions in all source files 2022-07-31 00:47:08 +02:00
fcin.h Update author attributions in all source files 2022-07-31 00:47:08 +02:00
history.h Update author attributions in all source files 2022-07-31 00:47:08 +02:00
io.h Update author attributions in all source files 2022-07-31 00:47:08 +02:00
jobs.h Re-backport atomic job locking from 93v- (re: 52067c3d, 595a0a56) 2022-08-01 05:41:52 +02:00
lexstates.h Update author attributions in all source files 2022-07-31 00:47:08 +02:00
name.h Update author attributions in all source files 2022-07-31 00:47:08 +02:00
national.h Update author attributions in all source files 2022-07-31 00:47:08 +02:00
nval.h Update author attributions in all source files 2022-07-31 00:47:08 +02:00
path.h Update author attributions in all source files 2022-07-31 00:47:08 +02:00
regress.h Update author attributions in all source files 2022-07-31 00:47:08 +02:00
shell.h Update author attributions in all source files 2022-07-31 00:47:08 +02:00
shlex.h Update author attributions in all source files 2022-07-31 00:47:08 +02:00
shnodes.h Update author attributions in all source files 2022-07-31 00:47:08 +02:00
shtable.h Update author attributions in all source files 2022-07-31 00:47:08 +02:00
streval.h Update author attributions in all source files 2022-07-31 00:47:08 +02:00
terminal.h Update author attributions in all source files 2022-07-31 00:47:08 +02:00
test.h Update author attributions in all source files 2022-07-31 00:47:08 +02:00
timeout.h Update author attributions in all source files 2022-07-31 00:47:08 +02:00
ulimit.h Update author attributions in all source files 2022-07-31 00:47:08 +02:00
variables.h remove ${.sh.pool} predefined variable entry (re: 3613da42) 2022-08-07 15:28:52 +01:00
version.h Fix history comment character in history expansion (re: 41ee12a5) 2022-08-16 22:00:20 +01:00