Skip to content

Commit 147df70

Browse files
authored
ed: avoid literal newline in s/// (briandfoy#917)
* Yesterday when editing a file I discovered the escape sequence "\n" was expanded to a newline when used in a substitution command * This has the unintended result of updating one or more elements of the lines-list to contain multiple newline characters * GNU and OpenBSD versions treat "\n" as a regular "n"; follow this for compatibility, and to avoid the problem of line x containing many lines
1 parent ce74886 commit 147df70

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

bin/ed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ sub edSubstitute {
550550
$PrintLastLine = 1;
551551
}
552552

553-
# do the search and substitution
553+
$args[0] =~ s/\\n/n/g; # newline is not permitted
554554
for my $lineno (@adrs) {
555555
my $evalstring = "\$lines[\$lineno] =~ s$args[0]";
556556

0 commit comments

Comments
 (0)