diff mbox series

[3/6] fc: only parse old=new if -s, per POSIX

Message ID 717f18e61d425cc96d2af5ac3f2c5f1de230f5d3.1675798292.git.nabijaczleweli@nabijaczleweli.xyz (mailing list archive)
State Accepted
Delegated to: Herbert Xu
Headers show
Series [1/6] fc -s: refuse multiple events instead of ignoring | expand

Commit Message

Ahelenia ZiemiaƄska Feb. 7, 2023, 7:33 p.m. UTC
Before (erroneously replaced):
	$ a=b set
	...
	$ fc a=b
	8
	,
	b=b set
After (used as search string):
	$ fc a=b
	8
	,
	a=b set

Reported-by: Harald van Dijk <harald@gigawatt.nl>
Reported-in: https://marc.info/?l=dash&m=154707728009743&w=2
---
 src/histedit.c | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)
diff mbox series

Patch

diff --git a/src/histedit.c b/src/histedit.c
index 28956ec..24631ca 100644
--- a/src/histedit.c
+++ b/src/histedit.c
@@ -288,21 +288,18 @@  histcmd(int argc, char **argv)
 	}
 
 	/*
-	 * If executing, parse [old=new] now
+	 * If -s is specified, accept [old=new] first only
 	 */
-	if (lflg == 0 && argc > 0 &&
-	     ((repl = strchr(argv[0], '=')) != NULL)) {
-		pat = argv[0];
-		*repl++ = '\0';
-		argc--, argv++;
+	if (sflg) {
+		if (argc > 0 && ((repl = strchr(argv[0], '=')) != NULL)) {
+			pat = argv[0];
+			*repl++ = '\0';
+			argc--, argv++;
+		}
+		if (argc >= 2)
+			sh_error("too many args");
 	}
 
-	/*
-	 * If -s is specified, accept only one operand
-	 */
-	if (sflg && argc >= 2)
-		sh_error("too many args");
-
 	/*
 	 * determine [first] and [last]
 	 */