java-diff-utils
java-diff-utils copied to clipboard
Regular expression in DiffUtils is too strict and will fail.
In DiffUtils, there is the following regular expression:
public class DiffUtils {
private static Pattern unifiedDiffChunkRe = Pattern
.compile("^@@\\s+-(?:(\\d+)(?:,(\\d+))?)\\s+\\+(?:(\\d+)(?:,(\\d+))?)\\s+@@$");
This will fail if there is a section header after the final @@ which is permitted. See https://en.wikipedia.org/wiki/Diff
"@@ -l,s +l,s @@ optional section heading"
This can be trivially fixed by replacing the regular expression with:
"^@@\\s+-(?:(\\d+)(?:,(\\d+))?)\\s+\\+(?:(\\d+)(?:,(\\d+))?)\\s+@@.*$"
... which will ignore the optional section heading.
Thanks for your project.