java-diff-utils / java-diff-utils

Diff Utils library is an OpenSource library for performing the comparison / diff operations between texts or some kind of data: computing diffs, applying patches, generating unified diffs or parsing them, generating diff output for easy future displaying (like side-by-side view) and so on.

Home Page:https://java-diff-utils.github.io/java-diff-utils/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

parseUnifiedDiff exception on valid diff (Binary files)

machadoit opened this issue · comments

Describe the bug
com.github.difflib.unifieddiff.UnifiedDiffReader#parseUnifiedDiff fails when the diff contains changes with Binaries.

To Reproduce

  1. Consider a diff with Binary changes, like adding a new test problem_diff_binary.diff with:
diff --git a/some-image.png b/some-image.png
new file mode 100644
index 0000000..bc3b5b4
Binary files /dev/null and b/some-image.png differ
  1. Invoke com.github.difflib.unifieddiff.UnifiedDiffReader#parseUnifiedDiff like a new test:
    @Test
    public void testParseBinary() throws IOException {
        UnifiedDiff diff = UnifiedDiffReader.parseUnifiedDiff(
                UnifiedDiffReaderTest.class.getResourceAsStream("problem_diff_binary.diff"));

        assertEquals(1, 1);
    }

By doing so, it returns an exception:

com.github.difflib.unifieddiff.UnifiedDiffReader processLine WARNING: >>> no rule matched Binary files /dev/null and b/some-image.png differ

Expected behavior
I would expect not to throw an exception, and that it would handle the Binary file entry as an UnifiedDiffFile

System
openjdk 17 2021-09-14
OpenJDK Runtime Environment Temurin-17+35 (build 17+35)
OpenJDK 64-Bit Server VM Temurin-17+35 (build 17+35, mixed mode, sharing)