From db047d72ee39222674197c28adb04e2107488d83 Mon Sep 17 00:00:00 2001 From: galaxy-designer Date: Tue, 3 Dec 2019 04:43:19 +0000 Subject: [PATCH] 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 --- internal/lsp/link.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/internal/lsp/link.go b/internal/lsp/link.go index 86e6084074..90d152fb34 100644 --- a/internal/lsp/link.go +++ b/internal/lsp/link.go @@ -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