diff-match-patch
diff-match-patch copied to clipboard
Fails to add newline after patch, fails to remove last character that needs to be removed
Given:
@@ -1,5 +1,5 @@
A
B
-C
+XYZ
D
-E
On file:
A
B
C
D
E
It returns 'A\nB\nXYZD\nE'
but should be 'A\nB\nXYZ\nD'
@stefanmatar it would be helpful if you provided the code you are using to get these results, especially showing the input values themselves and which functions you are calling with them.
@dmsnell we were using patch_apply(patches, text1) → [text2, results]
We moved over to the diff npm dependency in the meantime, as applied patches were not trustworthy.
@stefanmatar I'm attempting to reproduce this but I'm having patch
report an invalid patch file.
p.patch
--- a/a
+++ b/a
@@ -1,5 +1,5 @@
A
B
-C
+XYZ
D
-E
a
A
B
C
D
E
I've tried all four combinations of both files with and without a trailing newline
do you have patch <p.patch
working?
aha, actually @stefanmatar I think the problem is the range in the post-patch file. try using this valid patch instead.
@@ -1,5 +1,4 @@
A
B
-C
+XYZ
D
-E
granted, I think diff-match-patch
should probably abort if the patch is invalid, but this may explain why the output doesn't match what you expect
@dmsnell I agree, some kind of aborting would be best! There should be some kind of exception thrown