mirror of
https://github.com/golang/go
synced 2024-11-18 16:04:44 -07:00
internal/links: improve links parser, no protocol specification
The existing implementation has no consideration of links with no protocol specification, so "example.com/comments" now it's trated as "https://example.com/comments" "Fixes golang/go#33505" Corrects the regexp definition Change-Id: I587d611f26a3f3c5ea89eda7b2c3ccf369e8bb2f GitHub-Last-Rev: 740ffca04dd16b36a96f03781d58ff727e39ae79 GitHub-Pull-Request: golang/tools#154 Reviewed-on: https://go-review.googlesource.com/c/tools/+/194661 Reviewed-by: Rebecca Stambler <rstambler@golang.org>
This commit is contained in:
parent
8db96347c9
commit
db047d72ee
@ -91,13 +91,15 @@ func findLinksInString(src string, pos token.Pos, view source.View, mapper *prot
|
||||
if err != nil {
|
||||
return nil, errors.Errorf("cannot create regexp for links: %s", err.Error())
|
||||
}
|
||||
for _, urlIndex := range re.FindAllIndex([]byte(src), -1) {
|
||||
indexUrl := re.FindAllIndex([]byte(src), -1)
|
||||
for _, urlIndex := range indexUrl {
|
||||
var target string
|
||||
start := urlIndex[0]
|
||||
end := urlIndex[1]
|
||||
startPos := token.Pos(int(pos) + start)
|
||||
endPos := token.Pos(int(pos) + end)
|
||||
target := src[start:end]
|
||||
l, err := toProtocolLink(view, mapper, target, startPos, endPos)
|
||||
target = src[start:end]
|
||||
l, err := toProtocolLink(view, mapper, target, startPos, endPos)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -106,7 +108,7 @@ func findLinksInString(src string, pos token.Pos, view source.View, mapper *prot
|
||||
return links, nil
|
||||
}
|
||||
|
||||
const urlRegexpString = "(http|ftp|https)://([\\w_-]+(?:(?:\\.[\\w_-]+)+))([\\w.,@?^=%&:/~+#-]*[\\w@?^=%&/~+#-])?"
|
||||
const urlRegexpString = "((http|ftp|https)://)?([\\w_-]+(?:(?:\\.[\\w_-]+)+))([\\w.,@?^=%&:/~+#-]*[\\w@?^=%&/~+#-])?"
|
||||
|
||||
var (
|
||||
urlRegexp *regexp.Regexp
|
||||
|
Loading…
Reference in New Issue
Block a user