Skip to content

Commit 36dc118

Browse files
wxiaoguanglunnyKN4CK3Rzeripath
authored
Use correct captured group range when parsing cross-reference (#22672)
Fixes #22666 (Replace #22668) Co-authored-by: Lunny Xiao <[email protected]> Co-authored-by: KN4CK3R <[email protected]> Co-authored-by: zeripath <[email protected]>
1 parent f47ea60 commit 36dc118

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

modules/references/references.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ var (
3535
// issueAlphanumericPattern matches string that references to an alphanumeric issue, e.g. ABC-1234
3636
issueAlphanumericPattern = regexp.MustCompile(`(?:\s|^|\(|\[)([A-Z]{1,10}-[1-9][0-9]*)(?:\s|$|\)|\]|:|\.(\s|$))`)
3737
// crossReferenceIssueNumericPattern matches string that references a numeric issue in a different repository
38-
// e.g. gogits/gogs#12345
38+
// e.g. org/repo#12345
3939
crossReferenceIssueNumericPattern = regexp.MustCompile(`(?:\s|^|\(|\[)([0-9a-zA-Z-_\.]+/[0-9a-zA-Z-_\.]+[#!][0-9]+)(?:\s|$|\)|\]|[:;,.?!]\s|[:;,.?!]$)`)
4040
// crossReferenceCommitPattern matches a string that references a commit in a different repository
4141
// e.g. go-gitea/gitea@d8a994ef, go-gitea/gitea@d8a994ef243349f321568f9e36d5c3f444b99cae (7-40 characters)
4242
crossReferenceCommitPattern = regexp.MustCompile(`(?:\s|^|\(|\[)([0-9a-zA-Z-_\.]+)/([0-9a-zA-Z-_\.]+)@([0-9a-f]{7,40})(?:\s|$|\)|\]|[:;,.?!]\s|[:;,.?!]$)`)
43-
// spaceTrimmedPattern let's us find the trailing space
43+
// spaceTrimmedPattern let's find the trailing space
4444
spaceTrimmedPattern = regexp.MustCompile(`(?:.*[0-9a-zA-Z-_])\s`)
4545
// timeLogPattern matches string for time tracking
4646
timeLogPattern = regexp.MustCompile(`(?:\s|^|\(|\[)(@([0-9]+([\.,][0-9]+)?(w|d|m|h))+)(?:\s|$|\)|\]|[:;,.?!]\s|[:;,.?!]$)`)
@@ -365,7 +365,7 @@ func FindRenderizableCommitCrossReference(content string) (bool, *RenderizableRe
365365
Owner: content[m[2]:m[3]],
366366
Name: content[m[4]:m[5]],
367367
CommitSha: content[m[6]:m[7]],
368-
RefLocation: &RefSpan{Start: m[0], End: m[1]},
368+
RefLocation: &RefSpan{Start: m[2], End: m[7]},
369369
}
370370
}
371371

modules/references/references_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ func TestFindRenderizableCommitCrossReference(t *testing.T) {
352352
Owner: "go-gitea",
353353
Name: "gitea",
354354
CommitSha: "abcd1234",
355-
RefLocation: &RefSpan{Start: 4, End: 29},
355+
RefLocation: &RefSpan{Start: 5, End: 28},
356356
},
357357
},
358358
}

0 commit comments

Comments
 (0)