diff --git a/src/extractors.test.ts b/src/extractors.test.ts index bf523a1..d564fdd 100644 --- a/src/extractors.test.ts +++ b/src/extractors.test.ts @@ -117,6 +117,29 @@ describe("version suffix handling", () => { expect(ids(result)).toEqual(expected); }); + // A magic word in front of a version must not match a shorter prefix (ios-17.4 -> IOS-1) + it.each([ + ["Fix ios-17.4 keyboard crash", []], + ["Fix node-20.11 build", []], + ["Fixes ios-17.4.1 crash", []], + ["Fixes ENG-123, ENG-45.6", ["ENG-123"]], + ])("message %j should yield %j", (message, expected) => { + const result = extractLinearIssueIdentifiersForCommit({ + sha: "abc", + branchName: null, + message, + }); + expect(ids(result)).toEqual(expected); + }); + + it("does not report a version prefix as reverted", () => { + const result = extractRevertedIssueIdentifiersForCommit({ + sha: "abc", + message: 'Revert "Fix ios-17.4 keyboard crash"', + }); + expect(ids(result)).toEqual([]); + }); + // Legitimate identifiers should match it.each([ ["john/ios-1641-introduce-a-proper-blockview", ["IOS-1641"]], diff --git a/src/extractors.ts b/src/extractors.ts index 6dc54e6..276eb14 100644 --- a/src/extractors.ts +++ b/src/extractors.ts @@ -135,8 +135,10 @@ const CONTRIBUTING_PHRASES = [ /** * Core issue ID pattern without word boundaries — used inside the magic word * composite regex where surrounding context already provides boundaries. + * `(?![0-9])` stops the number from backtracking to a shorter prefix, which + * would otherwise let `ios-17.4` slip past the version lookahead as `ios-1`. */ -const ISSUE_ID_CORE = `\\w{1,${MAX_KEY_LENGTH}}-[0-9]{1,9}(?!\\.\\d)`; +const ISSUE_ID_CORE = `\\w{1,${MAX_KEY_LENGTH}}-[0-9]{1,9}(?![0-9])(?!\\.\\d)`; /** * Build a regex that matches magic words followed by one or more issue identifiers.