Closed
Description
@kpdecker your library is great so far. I think I might have found an edge case unless i'm missing something?
oldString = 'test\ntest2\n \ntest3\n';
"test
test2
test3
"
newString = 'test\ntest2\ntest3\n';
"test
test2
test3
"
Now I create a patch
d = JsDiff.createPatch('file/path.js', oldString, newString, '', '', { context: 0 });
This patch/diff looks correct
"Index: file/path.js
===================================================================
--- file/path.js
+++ file/path.js
@@ -3,1 +3,0 @@
-
However when I apply the patch....
result = JsDiff.applyPatch(oldString, d);
"test
test2
"
We can see it seems to be affecting the wrong line number. Is it trimming somewhere on the oldString where it shouldn't be?
Activity
Luiz-N commentedon Dec 14, 2016
UPDATE:
I've narrowed the scope of the bug down to when context is set to 0. So by setting it to 1 or higher it works correctly:
ibc commentedon Mar 14, 2017
Good catch. Same happens here.
bp-dev commentedon Jan 9, 2018
Also having problems with empty lines in 3 cases.
is not applied (and following blocks are applied in the wrong place as line numbers don't match anymore)
Pull request #212 fixes those cases (as far as I can test, comparing on a limited number of real-life samples with the behaviour of the linux patch command, which I would consider a good reference)
Luiz-N commentedon Jul 23, 2018
I think this got fixed with #212