java-diff-utils icon indicating copy to clipboard operation
java-diff-utils copied to clipboard

Regular expression in DiffUtils is too strict and will fail.

Open aleppard opened this issue 1 year ago • 0 comments

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.

aleppard avatar May 10 '23 08:05 aleppard