Skip to content

Commit 6a5ed23

Browse files
authored
ed: compatible \Z and \z in substitute
* Avoid special meaning of \Z and \z escapes when substituting text * The special meaning of \n was already prevented in this way * Add a missing call to get_terminated_line() in edSubstitute() that I found when testing this (the result of the s command is conditionally printed) * It is still possible to bind a substitution to the end of a line using s/$/RE/ * Tested against GNU ed
1 parent fc1a307 commit 6a5ed23

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

bin/ed

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,9 @@ sub edSubstitute {
548548
}
549549

550550
$args[0] =~ s/\\n/n/g; # newline is not permitted
551+
$args[0] =~ s/\\z/z/g;
552+
$args[0] =~ s/\\Z/Z/g;
553+
551554
for my $lineno (@adrs) {
552555
my $evalstring = "\$lines[\$lineno] =~ s$args[0]";
553556

@@ -561,7 +564,7 @@ sub edSubstitute {
561564
return E_NOMATCH unless defined $LastMatch;
562565
$CurrentLineNum = $LastMatch;
563566

564-
print $lines[$LastMatch] if ($PrintLastLine);
567+
print get_terminated_line($LastMatch) if $PrintLastLine;
565568
return;
566569
}
567570

0 commit comments

Comments
 (0)