Skip to content

Commit f2d8543

Browse files
authored
patch: parse 2-address append in ed-diff (#962)
* When processing an "a" (append text) command in an ed-style diff, line number ranges are not parsed correctly * If a range (e.g. "1,2") is given as a prefix to "a", the 2nd address ("2") is used as the target address * Regular diff tools don't output "a" commands with 2 addresses * ed-style diffs can be pasted from a previous ed editor session or typed manually, so having extra validation here is helpful * To test this, I bypassed the code for running an external ed program * I modified a diff generated by "diff -e", changing the "322a" command to "1,322a"... the file is patched successfully %cat bad.diffe 1,322a my $Maxlen = 1; # longest string for current directory . 317,318d 113d %perl patch -e ls bad.diffe Hmm... Looks like an ed diff to me... Patching file ls using Plan A... Hunk #1 succeeded at 113 Hunk #2 succeeded at 317 Hunk #3 succeeded at 322 done %cmp ls ls2
1 parent 7e33d43 commit f2d8543

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

bin/patch

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -997,6 +997,8 @@ sub apply {
997997
$cmd[$i] = '';
998998
s/\.\././ for @{$cmd[$i-1][3]};
999999
next;
1000+
} elsif ($cmd eq 'a') {
1001+
$start = $end if $start < $end; # "1,10a" takes 10 as target
10001002
}
10011003

10021004
# Remove '.' line used to terminate hunks.

0 commit comments

Comments
 (0)