Skip to content

applyPatch affecting wrong line number with with new lines #159

Description

@Luiz-N

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions