@@ -61,49 +61,51 @@ function compareAutolinks(a: Autolink, b: Autolink): number {
6161}
6262
6363export function ensureCachedRegex (
64- ref : CacheableAutolinkReference ,
64+ ref : Autolink | CacheableAutolinkReference ,
6565 outputFormat : 'html' ,
6666) : asserts ref is RequireSome < CacheableAutolinkReference , 'messageHtmlRegex' > ;
6767export function ensureCachedRegex (
68- ref : CacheableAutolinkReference ,
68+ ref : Autolink | CacheableAutolinkReference ,
6969 outputFormat : 'markdown' ,
7070) : asserts ref is RequireSome < CacheableAutolinkReference , 'messageMarkdownRegex' > ;
7171export function ensureCachedRegex (
72- ref : CacheableAutolinkReference ,
72+ ref : Autolink | CacheableAutolinkReference ,
7373 outputFormat : 'plaintext' ,
74- ) : asserts ref is RequireSome < CacheableAutolinkReference , 'messageRegex' | 'branchNameRegex' > ;
74+ ) : asserts ref is RequireSome < CacheableAutolinkReference , 'messageRegex' > ;
7575export function ensureCachedRegex (
76- ref : CacheableAutolinkReference ,
76+ ref : Autolink | CacheableAutolinkReference ,
7777 outputFormat : 'html' | 'markdown' | 'plaintext' ,
78- ) : boolean {
78+ ) : void {
79+ // If the ref is a matched Autolink then only match the exact `id`
80+ const refPattern = ref . id ? ref . id : ref . alphanumeric ? '\\w+' : '\\d+' ;
81+ const refFlags = ! ref . id && ref . ignoreCase ? 'gi' : 'g' ;
82+
7983 // Regexes matches the ref prefix followed by a token (e.g. #1234)
80- if ( outputFormat === 'markdown' && ref . messageMarkdownRegex == null ) {
84+ if ( outputFormat === 'markdown' ) {
8185 // Extra `\\\\` in `\\\\\\[` is because the markdown is escaped
82- ref . messageMarkdownRegex = new RegExp (
83- `(^|\\s|\\(|\\[|\\{)(${ escapeRegex ( encodeHtmlWeak ( escapeMarkdown ( ref . prefix ) ) ) } (${
84- ref . alphanumeric ? '\\w' : '\\d'
85- } +))\\b`,
86- ref . ignoreCase ? 'gi' : 'g' ,
87- ) ;
88- } else if ( outputFormat === 'html' && ref . messageHtmlRegex == null ) {
89- ref . messageHtmlRegex = new RegExp (
90- `(^|\\s|\\(|\\[|\\{)(${ escapeRegex ( encodeHtmlWeak ( ref . prefix ) ) } (${ ref . alphanumeric ? '\\w' : '\\d' } +))\\b` ,
91- ref . ignoreCase ? 'gi' : 'g' ,
86+ ref . messageMarkdownRegex ??= new RegExp (
87+ `(^|\\s|\\(|\\[|\\{)(${ escapeRegex ( encodeHtmlWeak ( escapeMarkdown ( ref . prefix ) ) ) } (${ refPattern } ))\\b` ,
88+ refFlags ,
9289 ) ;
93- } else if ( ref . messageRegex == null ) {
94- ref . messageRegex = new RegExp (
95- `(^|\\s|\\(|\\[|\\{)(${ escapeRegex ( ref . prefix ) } (${ ref . alphanumeric ? '\\w' : '\\d' } +))\\b` ,
96- ref . ignoreCase ? 'gi' : 'g' ,
97- ) ;
98- ref . branchNameRegex = new RegExp (
99- `(^|\\-|_|\\.|\\/)(?<prefix>${ ref . prefix } )(?<issueKeyNumber>${
100- ref . alphanumeric ? '\\w' : '\\d'
101- } +)(?=$|\\-|_|\\.|\\/)`,
102- 'gi' ,
90+ } else if ( outputFormat === 'html' ) {
91+ ref . messageHtmlRegex ??= new RegExp (
92+ `(^|\\s|\\(|\\[|\\{)(${ escapeRegex ( encodeHtmlWeak ( ref . prefix ) ) } (${ refPattern } ))\\b` ,
93+ refFlags ,
10394 ) ;
95+ } else {
96+ ref . messageRegex ??= new RegExp ( `(^|\\s|\\(|\\[|\\{)(${ escapeRegex ( ref . prefix ) } (${ refPattern } ))\\b` , refFlags ) ;
10497 }
98+ }
10599
106- return true ;
100+ export function ensureCachedBranchNameRegex (
101+ ref : CacheableAutolinkReference ,
102+ ) : asserts ref is RequireSome < CacheableAutolinkReference , 'branchNameRegex' > {
103+ ref . branchNameRegex ??= new RegExp (
104+ `(^|\\-|_|\\.|\\/)(?<prefix>${ ref . prefix } )(?<issueKeyNumber>${
105+ ref . alphanumeric ? '\\w' : '\\d'
106+ } +)(?=$|\\-|_|\\.|\\/)`,
107+ 'gi' ,
108+ ) ;
107109}
108110
109111export const numRegex = / < n u m > / g;
@@ -165,7 +167,7 @@ export function getBranchAutolinks(branchName: string, refsets: Readonly<RefSet[
165167 continue ;
166168 }
167169
168- ensureCachedRegex ( ref , 'plaintext' ) ;
170+ ensureCachedBranchNameRegex ( ref ) ;
169171 const matches = branchName . matchAll ( ref . branchNameRegex ) ;
170172 do {
171173 match = matches . next ( ) ;
0 commit comments