Skip to content

Commit

Permalink
fix checking the end of auto link boundary for linking commit URL
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysd committed Sep 30, 2024
1 parent 832d004 commit 7e07305
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
6 changes: 2 additions & 4 deletions reflink.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,9 @@ func (l *Reflinker) linkGitHubURL(n *ast.AutoLink, src []byte) {
}
start = t.Segment.Stop
}

label := n.Label(src)
stop := start + len(label)
if start >= len(src) || stop >= len(src) {
if start >= len(src) || stop > len(src) {
return
}
if src[start] == '<' && stop+1 < len(src) && src[stop+1] == '>' {
Expand All @@ -239,8 +238,7 @@ func (l *Reflinker) linkGitHubURL(n *ast.AutoLink, src []byte) {
return
}

slug := m[1]
hash := m[2]
slug, hash := m[1], m[2]
if len(hash) > 10 {
hash = hash[:10]
}
Expand Down
2 changes: 1 addition & 1 deletion reflink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ func TestLinkRefs(t *testing.T) {
{
what: "commit URL at end of text",
input: "test https://github.com/foo/bar/commit/1d457ba853aa10f9a6c925a1b73d5aed38066ffe",
want: "tes [`foo/bar@1d457ba853`](https://github.com/foo/bar/commit/1d457ba853aa10f9a6c925a1b73d5aed38066ffe)",
want: "test [`foo/bar@1d457ba853`](https://github.com/foo/bar/commit/1d457ba853aa10f9a6c925a1b73d5aed38066ffe)",
},
{
what: "commit URL with explicit auto link",
Expand Down

0 comments on commit 7e07305

Please sign in to comment.