]> source.dussan.org Git - gitea.git/commitdiff
Use correct captured group range when parsing cross-reference (#22672)
authorwxiaoguang <wxiaoguang@gmail.com>
Tue, 31 Jan 2023 09:08:05 +0000 (17:08 +0800)
committerGitHub <noreply@github.com>
Tue, 31 Jan 2023 09:08:05 +0000 (10:08 +0100)
Fixes #22666 (Replace #22668)

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: KN4CK3R <admin@oldschoolhack.me>
Co-authored-by: zeripath <art27@cantab.net>
modules/references/references.go
modules/references/references_test.go

index 1022e5af3d177cb07fa217b7d5bf9324056051d2..68662425cccf172d6ca56495bc5be4ae3d08039d 100644 (file)
@@ -35,12 +35,12 @@ var (
        // issueAlphanumericPattern matches string that references to an alphanumeric issue, e.g. ABC-1234
        issueAlphanumericPattern = regexp.MustCompile(`(?:\s|^|\(|\[)([A-Z]{1,10}-[1-9][0-9]*)(?:\s|$|\)|\]|:|\.(\s|$))`)
        // crossReferenceIssueNumericPattern matches string that references a numeric issue in a different repository
-       // e.g. gogits/gogs#12345
+       // e.g. org/repo#12345
        crossReferenceIssueNumericPattern = regexp.MustCompile(`(?:\s|^|\(|\[)([0-9a-zA-Z-_\.]+/[0-9a-zA-Z-_\.]+[#!][0-9]+)(?:\s|$|\)|\]|[:;,.?!]\s|[:;,.?!]$)`)
        // crossReferenceCommitPattern matches a string that references a commit in a different repository
        // e.g. go-gitea/gitea@d8a994ef, go-gitea/gitea@d8a994ef243349f321568f9e36d5c3f444b99cae (7-40 characters)
        crossReferenceCommitPattern = regexp.MustCompile(`(?:\s|^|\(|\[)([0-9a-zA-Z-_\.]+)/([0-9a-zA-Z-_\.]+)@([0-9a-f]{7,40})(?:\s|$|\)|\]|[:;,.?!]\s|[:;,.?!]$)`)
-       // spaceTrimmedPattern let's us find the trailing space
+       // spaceTrimmedPattern let's find the trailing space
        spaceTrimmedPattern = regexp.MustCompile(`(?:.*[0-9a-zA-Z-_])\s`)
        // timeLogPattern matches string for time tracking
        timeLogPattern = regexp.MustCompile(`(?:\s|^|\(|\[)(@([0-9]+([\.,][0-9]+)?(w|d|m|h))+)(?:\s|$|\)|\]|[:;,.?!]\s|[:;,.?!]$)`)
@@ -365,7 +365,7 @@ func FindRenderizableCommitCrossReference(content string) (bool, *RenderizableRe
                Owner:       content[m[2]:m[3]],
                Name:        content[m[4]:m[5]],
                CommitSha:   content[m[6]:m[7]],
-               RefLocation: &RefSpan{Start: m[0], End: m[1]},
+               RefLocation: &RefSpan{Start: m[2], End: m[7]},
        }
 }
 
index 1159e14b37ada7e915690416895043c998a974f9..75e002c99a3f8b42ee0b606acb16c97aa3ce6340 100644 (file)
@@ -352,7 +352,7 @@ func TestFindRenderizableCommitCrossReference(t *testing.T) {
                                Owner:       "go-gitea",
                                Name:        "gitea",
                                CommitSha:   "abcd1234",
-                               RefLocation: &RefSpan{Start: 4, End: 29},
+                               RefLocation: &RefSpan{Start: 5, End: 28},
                        },
                },
        }