Thanks to visit codestin.com
Credit goes to github.com

Skip to content

UnifiedDiffReader.parseUnifiedDiff(): Using unified diff with no prefix in file names leads to cut file names in some cases. #141

Closed
@IgnacioGarcia198

Description

@IgnacioGarcia198

Describe the bug
When using an unified diff with no a/, b/ prefix in file names as input for UnifiedDiffReader.parseUnifiedDiff(), extracted file names are cut when they start with one of a, b, old new. This seems to be due to this piece of code:

return line.substring(4).replaceFirst("^(a|b|old|new)(\\/)?", "")
                .trim();

which is located at UnifiedDiffReader::356 in a method called extractFileName.

To Reproduce
Steps to reproduce the behavior:

  1. Example data: Use an unified diff that contains at least one file whose name starts with "a", "b", "old" or "new".
    For example:
--- a.txt
+++ a1.txt
@@ -8,7 +8,7 @@
     <Setting>
         <Setting a>
             <setting b>
-                <value>23</value>
+                <value>24</value>
             </setting b>
             <setting c>
                 <value>1</value>
  1. simple program snippet
val diff = """
        --- a.txt
        +++ a1.txt
        @@ -8,7 +8,7 @@
             <Setting>
                 <Setting a>
                     <setting b>
        -                <value>23</value>
        +                <value>24</value>
                     </setting b>
                     <setting c>
                         <value>1</value>
    """.trimIndent()
val unifiedDiff = UnifiedDiffReader.parseUnifiedDiff(diff.byteInputStream())
unifiedDiff.files.forEach { unifiedDiffFile ->
                println(unifiedDiffFile.fromFile)
                println(unifiedDiffFile.toFile)
}
  1. See error

This snipet prints:

.txt
1.txt

Expected behavior
The snippet should print:

a.txt
a1.txt

System

  • Java version 11
  • Version 4.11

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