Skip to content

Commit ededee0

Browse files
committed
1 parent eada27b commit ededee0

File tree

5 files changed

+51
-4
lines changed

5 files changed

+51
-4
lines changed

java-diff-utils/nb-configuration.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project-shared-configuration>
3+
<!--
4+
This file contains additional configuration written by modules in the NetBeans IDE.
5+
The configuration is intended to be shared among all the users of project and
6+
therefore it is assumed to be part of version control checkout.
7+
Without this configuration present, some functionality in the IDE may be limited or fail altogether.
8+
-->
9+
<properties xmlns="http://www.netbeans.org/ns/maven-properties-data/1">
10+
<!--
11+
Properties that influence various parts of the IDE, especially code formatting and the like.
12+
You can copy and paste the single properties, into the pom.xml file and the IDE will pick them up.
13+
That way multiple projects can share the same settings (useful for formatting rules for example).
14+
Any value defined here will override the pom.xml file value but is only applicable to the current project.
15+
-->
16+
<netbeans.hint.jdkPlatform>JDK_1.8</netbeans.hint.jdkPlatform>
17+
</properties>
18+
</project-shared-configuration>

java-diff-utils/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
5050
<manifestEntries>
5151
<!-- identical to OSGI name -->
52-
<Automatic-Module-Name>io.github.java-diff-utils</Automatic-Module-Name>
52+
<Automatic-Module-Name>io.github.javadiffutils</Automatic-Module-Name>
5353
</manifestEntries>
5454
</archive>
5555
</configuration>

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ private UnifiedDiff parse() throws IOException, UnifiedDiffParserException {
9797
if (processLine(line, LINE_NORMAL, LINE_ADD, LINE_DEL) == false) {
9898
throw new UnifiedDiffParserException("expected data line not found");
9999
}
100-
if (originalTxt.size() == old_size && revisedTxt.size() == new_size) {
100+
if ((originalTxt.size() == old_size && revisedTxt.size() == new_size)
101+
|| (old_size==0 && new_size==0 && originalTxt.size() == this.old_ln
102+
&& revisedTxt.size() == this.new_ln)) {
101103
finalizeChunk();
102104
break;
103105
}
@@ -241,9 +243,9 @@ private String extractFileName(String _line) {
241243
Matcher matcher = TIMESTAMP_REGEXP.matcher(_line);
242244
String line = _line;
243245
if (matcher.find()) {
244-
line = line.substring(1, matcher.start());
246+
line = line.substring(0, matcher.start());
245247
}
246-
return line.substring(4).replaceFirst("^(a|b)\\/", "")
248+
return line.substring(4).replaceFirst("^(a|b|old|new)(\\/)?", "")
247249
.replace(TIMESTAMP_REGEXP.toString(), "").trim();
248250
}
249251

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,20 @@ public void testParseIssue33() throws IOException {
141141
assertThat(diff.getTail()).isNull();
142142
assertThat(diff.getHeader()).isNull();
143143
}
144+
145+
@Test
146+
public void testParseIssue51() throws IOException {
147+
UnifiedDiff diff = UnifiedDiffReader.parseUnifiedDiff(
148+
UnifiedDiffReaderTest.class.getResourceAsStream("problem_diff_issue51.diff"));
149+
150+
System.out.println(diff);
151+
152+
assertThat(diff.getFiles().size()).isEqualTo(2);
153+
154+
UnifiedDiffFile file1 = diff.getFiles().get(0);
155+
assertThat(file1.getFromFile()).isEqualTo("f1");
156+
assertThat(file1.getPatch().getDeltas().size()).isEqualTo(1);
157+
158+
assertThat(diff.getTail()).isNull();
159+
}
144160
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
diff -U0 old/f1 new/f1
2+
--- old/f1 2019-09-25 14:38:06.000000000 +0200
3+
+++ new/f1 2019-09-25 14:38:27.000000000 +0200
4+
@@ -1 +1 @@
5+
-a\nb
6+
+a\nb\nd
7+
diff -U0 old/f2 new/f2
8+
--- old/f2 2019-09-25 14:38:14.000000000 +0200
9+
+++ new/f2 2019-09-25 14:38:32.000000000 +0200
10+
@@ -1 +1 @@
11+
-a\nc

0 commit comments

Comments
 (0)