Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails to add newline after patch, fails to remove last character that needs to be removed #147

Open
stefanmatar opened this issue Jul 17, 2023 · 5 comments

Comments

@stefanmatar
Copy link

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 stefanmatar changed the title Fails to remove lines if there are more lines added than previously existed Fails to add newline after patch, fails to remove last character that needs to be removed Jul 17, 2023
@dmsnell
Copy link

dmsnell commented Jul 17, 2023

@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.

@stefanmatar
Copy link
Author

@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.

@dmsnell
Copy link

dmsnell commented Sep 29, 2023

@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?

@dmsnell
Copy link

dmsnell commented Sep 29, 2023

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

@stefanmatar
Copy link
Author

@dmsnell I agree, some kind of aborting would be best! There should be some kind of exception thrown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants