commit f6a1fbb9b1c6b5058371daeeb903a7e7a3643bbd
parent beb6a2fa2aeaa9791738510097231e7e9da45f47
Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
Date: Mon, 8 Dec 2025 17:54:10 +0100
ed: Restore newlines in match()
Match was removing the trailing newline to fix some problems
in regex, but this modified the content of the line making
that the output file had embedded NUL characters (and obviously
no newlines).
Diffstat:
2 files changed, 24 insertions(+), 1 deletion(-)
diff --git a/ed.c b/ed.c
@@ -442,9 +442,14 @@ compile(int delim)
static int
match(int num)
{
+ int r;
+
lastmatch = gettxt(num);
text.str[text.siz - 2] = '\0';
- return !regexec(pattern, lastmatch, 10, matchs, 0);
+ r =!regexec(pattern, lastmatch, 10, matchs, 0);
+ text.str[text.siz - 2] = '\n';
+
+ return r;
}
static int
diff --git a/tests/0008-ed.sh b/tests/0008-ed.sh
@@ -0,0 +1,18 @@
+#!/bin/sh
+
+set -e
+
+tmp=tmp.$$
+
+trap 'rm -f $tmp' EXIT
+trap 'rm -f $tmp; kill -KILL $$' HUP INT TERM
+
+../ed <<EOF > /dev/null
+0a
+This is important
+.
+s/^@//
+w $tmp
+EOF
+
+echo 'This is important' | diff -u - $tmp