Skip to content

Regular expression in DiffUtils is too strict and will fail. #41

@aleppard

Description

@aleppard

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions