Skip to content

Commit ea9942d

Browse files
authored
Fix for #141 (#144)
* Add test to reproduce issue #141 * Fix assumption on test to match expected behaviour expressed on #141 * Make "/" after "virtual" directories mandatory Now the regex only matches with "a/", "b/", "new/" and "old/", previously the slash was taken as optional. fixes #141
1 parent 8fdd239 commit ea9942d

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

java-diff-utils/src/main/java/com/github/difflib/unifieddiff/UnifiedDiffReader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ private String extractFileName(String _line) {
353353
line = line.substring(0, matcher.start());
354354
}
355355
line = line.split("\t")[0];
356-
return line.substring(4).replaceFirst("^(a|b|old|new)(\\/)?", "")
356+
return line.substring(4).replaceFirst("^(a|b|old|new)/", "")
357357
.trim();
358358
}
359359

java-diff-utils/src/test/java/com/github/difflib/unifieddiff/UnifiedDiffReaderTest.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public void testParseIssue46() throws IOException {
122122
assertThat(diff.getFiles().size()).isEqualTo(1);
123123

124124
UnifiedDiffFile file1 = diff.getFiles().get(0);
125-
assertThat(file1.getFromFile()).isEqualTo(".vhd");
125+
assertThat(file1.getFromFile()).isEqualTo("a.vhd");
126126
assertThat(file1.getPatch().getDeltas().size()).isEqualTo(1);
127127

128128
assertThat(diff.getTail()).isNull();
@@ -384,4 +384,14 @@ public void testParseIssue123() throws IOException {
384384

385385
assertThat(diff.getFiles()).extracting(f -> f.getFromFile()).contains("src/java/main/org/apache/zookeeper/server/FinalRequestProcessor.java");
386386
}
387+
388+
@Test
389+
public void testParseIssue141() throws IOException {
390+
UnifiedDiff diff = UnifiedDiffReader.parseUnifiedDiff(
391+
UnifiedDiffReaderTest.class.getResourceAsStream("problem_diff_issue141.diff"));
392+
UnifiedDiffFile file1 = diff.getFiles().get(0);
393+
394+
assertThat(file1.getFromFile()).isEqualTo("a.txt");
395+
assertThat(file1.getToFile()).isEqualTo("a1.txt");
396+
}
387397
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--- a.txt
2+
+++ a1.txt
3+
@@ -8,7 +8,7 @@
4+
<Setting>
5+
<Setting a>
6+
<setting b>
7+
- <value>23</value>
8+
+ <value>24</value>
9+
</setting b>
10+
<setting c>
11+
<value>1</value>

0 commit comments

Comments
 (0)