On Monday 10 May 2010 06:38, Rob Landley wrote:
> echo -e '\t| one \\\n\t| two \\\n' | sed -e '/| one /a \
>         | three \\' -e '/| one-/a \
>         | three-* \\'
> 
> The above behaves differently on busybox and gnu seds.
> 
> I've meant to fix it all weekend, but was too busy.  Just thought I'd post it 
> here so it wouldn't get lost...

Please try attached patch.

-- 
vda
diff -ad -urpN busybox.8/editors/sed.c busybox.9/editors/sed.c
--- busybox.8/editors/sed.c	2010-05-10 04:21:13.000000000 +0200
+++ busybox.9/editors/sed.c	2010-05-12 01:38:14.000000000 +0200
@@ -487,7 +487,7 @@ static const char *parse_cmd_args(sed_cm
 static void add_cmd(const char *cmdstr)
 {
 	sed_cmd_t *sed_cmd;
-	int temp;
+	unsigned len, n;
 
 	/* Append this line to any unfinished line from last time. */
 	if (G.add_cmd_line) {
@@ -496,12 +496,14 @@ static void add_cmd(const char *cmdstr)
 		cmdstr = G.add_cmd_line = tp;
 	}
 
-	/* If this line ends with backslash, request next line. */
-	temp = strlen(cmdstr);
-	if (temp && cmdstr[--temp] == '\\') {
+	/* If this line ends with unescaped backslash, request next line. */
+	n = len = strlen(cmdstr);
+	while (n && cmdstr[n-1] == '\\')
+		n--;
+	if ((len - n) & 1) { /* if odd number of trailing backslashes */
 		if (!G.add_cmd_line)
 			G.add_cmd_line = xstrdup(cmdstr);
-		G.add_cmd_line[temp] = '\0';
+		G.add_cmd_line[len-1] = '\0';
 		return;
 	}
 
diff -ad -urpN busybox.8/testsuite/sed.tests busybox.9/testsuite/sed.tests
--- busybox.8/testsuite/sed.tests	2010-05-10 04:21:14.000000000 +0200
+++ busybox.9/testsuite/sed.tests	2010-05-12 01:34:29.000000000 +0200
@@ -258,4 +258,18 @@ testing "sed nested {}s" \
 	"qwe\nasd\nacd\nacd\n" "" \
 	"qwe\nasd\nzxc\n"
 
+testing "sed a cmd ended by double backslash" \
+	"sed -e '/| one /a \\
+	| three \\\\' -e '/| one-/a \\
+	| three-* \\\\'" \
+'	| one \\
+	| three \\
+	| two \\
+' '' \
+'	| one \\
+	| two \\
+'
+
+# testing "description" "arguments" "result" "infile" "stdin"
+
 exit $FAILCOUNT
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to