TypeScript
fix(github): long period runs no longer freeze reference autolinking (#26177)
Julius Marmingef0c1da3b5f47
diff --git a/packages/source-control-github/src/shared/referenceAutolinks.test.ts b/packages/source-control-github/src/shared/referenceAutolinks.test.tsindex c3ce130b909..288264a4929 100644--- a/packages/source-control-github/src/shared/referenceAutolinks.test.ts+++ b/packages/source-control-github/src/shared/referenceAutolinks.test.ts@@ -36,6 +36,19 @@ describe("gitHubReferenceAutolinks", () => {);});+ it("scans long runs of periods and dashes in linear time", () => {+ expect(linked(`${".".repeat(50_000)} ${".-".repeat(25_000)} #1`)).toEqual([+ ["#1", "https://github.com/team/repo/issues/1", "reference"],+ ]);+ });++ it("links references that follow punctuation", () => {+ expect(linked("(#5), owner.name/repo-x#3")).toEqual([+ ["#5", "https://github.com/team/repo/issues/5", "reference"],+ ["owner.name/repo-x#3", "https://github.com/owner.name/repo-x/issues/3", "reference"],+ ]);+ });+it("links against the repository's own host", () => {expect(gitHubReferenceAutolinks("See #5", "https://ghe.example.com/acme/web").map(({ url }) => url),diff --git a/packages/source-control-github/src/shared/referenceAutolinks.ts b/packages/source-control-github/src/shared/referenceAutolinks.tsindex ebf31d86e17..2c9fb185580 100644--- a/packages/source-control-github/src/shared/referenceAutolinks.ts+++ b/packages/source-control-github/src/shared/referenceAutolinks.ts@@ -3,7 +3,7 @@ import type { ReferenceAutolink } from "@t3tools/source-control-core/shared/defi// GitHub's autolinked references: `#12`, `repo#12` and `owner/repo#12`; a SHA of 7 to 40// characters, optionally `repo@` or `owner/repo@` qualified; `@user` and `@org/team`.const REFERENCE =- /(?<![\w/\\])(?:([\w.-]+\/[\w.-]+|[\w-]+)?#([1-9]\d*)|(?:([\w.-]+\/[\w.-]+|[\w-]+)@)?([a-f\d]{7,40})(?![\w])|@([a-z\d](?:[a-z\d-]*[a-z\d])?(?:\/[a-z\d][a-z\d-]*)?))(?![\w])/giu;+ /(?<![\w./\\-])(?:([\w.-]+\/[\w.-]+|[\w-]+)?#([1-9]\d*)|(?:([\w.-]+\/[\w.-]+|[\w-]+)@)?([a-f\d]{7,40})(?![\w])|@([a-z\d](?:[a-z\d-]*[a-z\d])?(?:\/[a-z\d][a-z\d-]*)?))(?![\w])/giu;const CANDIDATE = /[#@]|\b[a-f\d]{7,40}\b/iu;const SHORT_SHA_LENGTH = 7;