← 返回首页
UnifiedDiffReader.parseUnifiedDiff(): Using unified diff with no prefix in file names leads to cut file names in some cases. · Issue #141 · java-diff-utils/java-diff-utils · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus

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

New issue
New issue

Description

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

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    • Open in GitHub Copilot app

    Footer

    © 2026 GitHub, Inc.