Subject: bug#23635: possible bug in \c escape handling

From: Jim Meyering <[email-masked]>
Date: Sat, 28 May 2016 20:40:24 -0700

On Sat, May 28, 2016 at 7:31 PM, Assaf Gordon <[email-masked]> wrote:
> Hello,
>
> Thank you for the review.
> Attached an improved version.
>
> Regarding when the bug was introduced (in the 'NEWS'), version 3.02 did not support \c escapes, and version 4.0.6 had this bug (as does the first git commit). I wrote:
>     [bug introduced in the sed-4.0.* releases]

Thanks for the quick update!
One more thing I noticed is that you use here docs
that interpolate. Just as I prefer to use single-quoted strings
most of the time, e.g., to avoid having to backslash-escape
every backslash, I prefer to use quoted here docs as in the
attached. Also, I prefer to space-delimit operators like '<', '<<', and '>'.
At least on one side.

Also, I removed a stray "EOF" after the final "Exit..." line.

Here's the proposed delta, on top of your patch:
diff --git a/testsuite/recursive-escape-c.sh b/testsuite/recursive-escape-c.sh
index cea9c06..95d007b 100644
--- a/testsuite/recursive-escape-c.sh
+++ b/testsuite/recursive-escape-c.sh
@@ -26,22 +26,20 @@ export LC_ALL=C
 printf "%s\n" a a a a a a >in1 || framework_failure_

 # input program
-# (NOTE: every two-backslashes in the here-doc result
-#  in one backslash in the file)
-cat<<EOF>prog1 || framework_failure_
-1s/./\\cA/
-2s/./\\cB/
-3s/./\\c[/
-4s/./\\c]/
+cat << \EOF > prog1 || framework_failure_
+1s/./\cA/
+2s/./\cB/
+3s/./\c[/
+4s/./\c]/

 # '\c' at end-of-buffer, a backslash is pushed up
 # on level of interpretation, and the '.' match is replaced
 # with one backslash.
-5s/./\\c/
+5s/./\c/

 # This would return incorrect results before 4.3,
 # producing both \034 and another backslash.
-6s/./\\c\\\\/
+6s/./\c\\/
 EOF

 # expected output:
@@ -63,7 +61,7 @@ fi
 #
 # Test invalid usage
 #
-cat<<EOF>exp-err || framework_failure_
+cat << \EOF > exp-err || framework_failure_
 sed: -e expression #1, char 10: recursive escaping after \c not allowed
 EOF

@@ -72,4 +70,3 @@ returns_ 1 sed '1s/./\c\d/' in1 2>err || fail=1
 compare_ exp-err err || fail=1

 Exit $fail
-EOF