Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
aleppard opened this issue May 10, 2023 · 0 comments
Open

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

aleppard opened this issue May 10, 2023 · 0 comments

Comments

@aleppard
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant