svn commit: trunk/busybox: editors testsuite
vda at busybox.net
vda at busybox.net
Fri Mar 16 23:36:58 UTC 2007
Author: vda
Date: 2007-03-16 16:36:58 -0700 (Fri, 16 Mar 2007)
New Revision: 18128
Log:
sed: fix very obscure case of escaped newline in sed command
(needed for uclibc build, btw). Add testcase for it.
Modified:
trunk/busybox/editors/sed.c
trunk/busybox/testsuite/sed.tests
Changeset:
Modified: trunk/busybox/editors/sed.c
===================================================================
--- trunk/busybox/editors/sed.c 2007-03-16 19:38:14 UTC (rev 18127)
+++ trunk/busybox/editors/sed.c 2007-03-16 23:36:58 UTC (rev 18128)
@@ -1175,21 +1175,38 @@
}
/* It is possible to have a command line argument with embedded
- newlines. This counts as multiple command lines. */
+ * newlines. This counts as multiple command lines.
+ * However, newline can be escaped: 's/e/z\<newline>z/'
+ * We check for this.
+ */
static void add_cmd_block(char *cmdstr)
{
- int go = 1;
- char *temp = xstrdup(cmdstr), *temp2 = temp;
+ char *sv, *eol;
- while (go) {
- int len = strcspn(temp2, "\n");
- if (!temp2[len]) go = 0;
- else temp2[len] = 0;
- add_cmd(temp2);
- temp2 += len+1;
- }
- free(temp);
+ cmdstr = sv = xstrdup(cmdstr);
+ do {
+ eol = strchr(cmdstr, '\n');
+ next:
+ if (eol) {
+ /* Count preceding slashes */
+ int slashes = 0;
+ char *sl = eol;
+
+ while (sl != cmdstr && *--sl == '\\')
+ slashes++;
+ /* Odd number of preceding slashes - newline is escaped */
+ if (slashes & 1) {
+ strcpy(eol-1, eol);
+ eol = strchr(eol, '\n');
+ goto next;
+ }
+ *eol = '\0';
+ }
+ add_cmd(cmdstr);
+ cmdstr = eol + 1;
+ } while (eol);
+ free(sv);
}
static void add_cmds_link(llist_t *opt_e)
Modified: trunk/busybox/testsuite/sed.tests
===================================================================
--- trunk/busybox/testsuite/sed.tests 2007-03-16 19:38:14 UTC (rev 18127)
+++ trunk/busybox/testsuite/sed.tests 2007-03-16 23:36:58 UTC (rev 18128)
@@ -146,6 +146,10 @@
testing "sed trailing NUL" \
"sed 's/i/z/' input -" \
"a\0b\0\nc" "a\0b\0" "c"
+testing "sed escaped newline in command" \
+ "sed 's/a/z\\
+z/' input" \
+ "z\nz" "a" ""
# Test end-of-file matching behavior
More information about the busybox-cvs
mailing list