Closed
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:
- 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>
- 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)
}
- 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
Labels
No labels