Skip to content
This repository was archived by the owner on Aug 5, 2024. It is now read-only.
This repository was archived by the owner on Aug 5, 2024. It is now read-only.

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

Description

@stefanmatar

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'

Activity

  1. 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[/+] on Jul 17, 2023
  2. dmsnell commented on Jul 17, 2023

    @dmsnell

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

  3. stefanmatar commented on Sep 29, 2023

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

  4. dmsnell commented on Sep 29, 2023

    @dmsnell

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

  5. dmsnell commented on Sep 29, 2023

    @dmsnell

    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

  6. stefanmatar commented on Oct 25, 2023

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions