Module Name:    src
Committed By:   kre
Date:           Sat Aug  5 11:33:05 UTC 2017

Modified Files:
        src/bin/sh: input.c parser.c

Log Message:
PR bin/52458

Avoid mangling history when editing is enabled, and the prompt contains a \n

Also, allow empty input lines into history when they are being appended to
a previous (partial) command (but not when they would just make an empty entry).

For all the gory details, see the PR.

Note nothing here actually makes prompts containing \n work correctly
when editing is enabled, that's a libedit issue, which will be addressed
some other time.


To generate a diff of this commit:
cvs rdiff -u -r1.60 -r1.61 src/bin/sh/input.c
cvs rdiff -u -r1.142 -r1.143 src/bin/sh/parser.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/bin/sh/input.c
diff -u src/bin/sh/input.c:1.60 src/bin/sh/input.c:1.61
--- src/bin/sh/input.c:1.60	Wed Jul  5 19:54:21 2017
+++ src/bin/sh/input.c	Sat Aug  5 11:33:05 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: input.c,v 1.60 2017/07/05 19:54:21 kre Exp $	*/
+/*	$NetBSD: input.c,v 1.61 2017/08/05 11:33:05 kre Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)input.c	8.3 (Berkeley) 6/9/95";
 #else
-__RCSID("$NetBSD: input.c,v 1.60 2017/07/05 19:54:21 kre Exp $");
+__RCSID("$NetBSD: input.c,v 1.61 2017/08/05 11:33:05 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -310,10 +310,11 @@ preadbuffer(void)
 	*q = '\0';
 
 #ifndef SMALL
-	if (parsefile->fd == 0 && hist && something) {
+	if (parsefile->fd == 0 && hist && (something || whichprompt == 2)) {
 		HistEvent he;
+
 		INTOFF;
-		history(hist, &he, whichprompt == 1? H_ENTER : H_APPEND,
+		history(hist, &he, whichprompt != 2 ? H_ENTER : H_APPEND,
 		    parsenextc);
 		INTON;
 	}

Index: src/bin/sh/parser.c
diff -u src/bin/sh/parser.c:1.142 src/bin/sh/parser.c:1.143
--- src/bin/sh/parser.c:1.142	Wed Jul 26 23:09:41 2017
+++ src/bin/sh/parser.c	Sat Aug  5 11:33:05 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: parser.c,v 1.142 2017/07/26 23:09:41 kre Exp $	*/
+/*	$NetBSD: parser.c,v 1.143 2017/08/05 11:33:05 kre Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)parser.c	8.7 (Berkeley) 5/16/95";
 #else
-__RCSID("$NetBSD: parser.c,v 1.142 2017/07/26 23:09:41 kre Exp $");
+__RCSID("$NetBSD: parser.c,v 1.143 2017/08/05 11:33:05 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -2192,13 +2192,14 @@ getprompt(void *unused)
 {
 	char *p;
 	const char *cp;
+	int wp;
 
 	if (!doprompt)
 		return "";
 
 	VTRACE(DBG_PARSE|DBG_EXPAND, ("getprompt %d\n", whichprompt));
 
-	switch (whichprompt) {
+	switch (wp = whichprompt) {
 	case 0:
 		return "";
 	case 1:
@@ -2216,6 +2217,7 @@ getprompt(void *unused)
 	VTRACE(DBG_PARSE|DBG_EXPAND, ("prompt <<%s>>\n", p));
 
 	cp = expandstr(p, plinno);
+	whichprompt = wp;	/* history depends on it not changing */
 
 	VTRACE(DBG_PARSE|DBG_EXPAND, ("prompt -> <<%s>>\n", cp));
 

Reply via email to