diff mbox series

input: Only skip blank lines on PS1

Message ID Y7Z7kiVnwF+sltL+@gondor.apana.org.au (mailing list archive)
State Accepted
Delegated to: Herbert Xu
Headers show
Series input: Only skip blank lines on PS1 | expand

Commit Message

Herbert Xu Jan. 5, 2023, 7:26 a.m. UTC
On Wed, Jan 04, 2023 at 11:18:49AM +0000, Harald van Dijk wrote:
> 
> One is that because of what you say, the history recording for commands
> greater than BUFSIZ is already buggy, but unlikely to pose a problem in
> practice currently because normally, people don't write such long commands.

It's not just that people don't write long lines, it's the fact
that most people use the shell with a terminal device in canonical
mode and the line length is capped in canonical mode to some value
less than 8K.

> Another is that the stripping of blank lines from history breaks when blank
> lines are significant, as in
> 
>   $ cat <<EOF
>   > hello
>   >
>   > world
>   > EOF
>   hello
> 
>   world
>   $ fc 1
>   26
>   q
>   hello
>   world
> 
> Note how the blank line was lost.
> 
> If there was already "something" (as the code puts it), then when more data
> is appended, blanks must be preserved.

Good point.  This patch should fix it.

---8<---
Blank line should not be skipped if they're found on PS2.

Reported-by: Harald van Dijk <harald@gigawatt.nl>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Comments

Harald van Dijk Jan. 5, 2023, 8:33 a.m. UTC | #1
On 05/01/2023 07:26, Herbert Xu wrote:
> On Wed, Jan 04, 2023 at 11:18:49AM +0000, Harald van Dijk wrote:
>>
>> One is that because of what you say, the history recording for commands
>> greater than BUFSIZ is already buggy, but unlikely to pose a problem in
>> practice currently because normally, people don't write such long commands.
> 
> It's not just that people don't write long lines, it's the fact
> that most people use the shell with a terminal device in canonical
> mode and the line length is capped in canonical mode to some value
> less than 8K.

Remember that we're talking about builds of dash here with libedit 
support, as otherwise history is disabled anyway. In builds with libedit 
support, I would imagine the more common use is that libedit is used for 
entry, in which case the terminal is *not* in canonical mode.

Cheers,
Harald van Dijk
diff mbox series

Patch

diff --git a/src/input.c b/src/input.c
index 7b37ae2..5dcc8a2 100644
--- a/src/input.c
+++ b/src/input.c
@@ -254,6 +254,7 @@  retry:
 
 static int preadbuffer(void)
 {
+	int first = whichprompt == 1;
 	int something;
 	char savec;
 	int more;
@@ -279,7 +280,7 @@  again:
 	q = parsefile->nextc;
 
 	/* delete nul characters */
-	something = 0;
+	something = !first;
 	for (;;) {
 		int c;
 
@@ -327,7 +328,7 @@  check:
 	if (parsefile->fd == 0 && hist && something) {
 		HistEvent he;
 		INTOFF;
-		history(hist, &he, whichprompt == 1? H_ENTER : H_APPEND,
+		history(hist, &he, first ? H_ENTER : H_APPEND,
 			parsefile->nextc);
 		INTON;
 	}