From 8c65a37a28fe2c2466703e234fa223e0b60a4e08 Mon Sep 17 00:00:00 2001 From: Kevin de Jong Date: Mon, 17 Jun 2024 17:10:11 +0200 Subject: [PATCH] fix: reduce ambiguity of merge-regex patterns The branch-name patterns used in the merge-commit regex's are now constraint to the allowed characters in git branch names. This improves overall performance of the regex matcher. --- src/commit.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/commit.ts b/src/commit.ts index 6abd35b..d803f45 100644 --- a/src/commit.ts +++ b/src/commit.ts @@ -202,9 +202,9 @@ export function getFooterElementsFromParagraph( * @returns True if the subject is a common merge pattern, false otherwise */ function subjectIsMergePattern(subject: string): boolean { - const githubMergeRegex = /^Merge pull request #(\d+) from '?(.*)'?$/; - const bitbucketMergeRegex = /^Merged in '?(.*)'? \(pull request #(\d+)\)$/; - const gitlabMergeRegex = /^Merge( remote-tracking)? branch '?(.*?)'? into '?(.*?)'?$/; + const githubMergeRegex = /^Merge pull request #(\d+) from '?([a-zA-Z0-9_./-]+)'?$/; + const bitbucketMergeRegex = /^Merged in '?([a-zA-Z0-9_./-]+)'? \(pull request #(\d+)\)$/; + const gitlabMergeRegex = /^Merge( remote-tracking)? branch '?([a-zA-Z0-9_./-]+)'?? into '?([a-zA-Z0-9_./-]+)'?$/; return githubMergeRegex.test(subject) || bitbucketMergeRegex.test(subject) || gitlabMergeRegex.test(subject); }