diff --git a/go/vcs/discovery.go b/go/vcs/discovery.go index f431dc1c..2428d888 100644 --- a/go/vcs/discovery.go +++ b/go/vcs/discovery.go @@ -28,13 +28,16 @@ func charsetReader(charset string, input io.Reader) (io.Reader, error) { // parseMetaGoImports returns meta imports from the HTML in r. // Parsing ends at the end of the section or the beginning of the . +// +// This copy of cmd/go/internal/vcs.parseMetaGoImports always operates +// in IgnoreMod ModuleMode. func parseMetaGoImports(r io.Reader) (imports []metaImport, err error) { d := xml.NewDecoder(r) d.CharsetReader = charsetReader d.Strict = false var t xml.Token for { - t, err = d.Token() + t, err = d.RawToken() if err != nil { if err == io.EOF || len(imports) > 0 { err = nil @@ -55,6 +58,10 @@ func parseMetaGoImports(r io.Reader) (imports []metaImport, err error) { continue } if f := strings.Fields(attrValue(e.Attr, "content")); len(f) == 3 { + // Ignore VCS type "mod", which is applicable only in module mode. + if f[1] == "mod" { + continue + } imports = append(imports, metaImport{ Prefix: f[0], VCS: f[1], diff --git a/go/vcs/vcs_test.go b/go/vcs/vcs_test.go index d18ff18e..b725f018 100644 --- a/go/vcs/vcs_test.go +++ b/go/vcs/vcs_test.go @@ -116,6 +116,20 @@ var parseMetaGoImportsTests = []struct { {"baz/quux", "git", "http://github.com/rsc/baz/quux"}, }, }, + { + ` + `, + []metaImport{ + {"foo/bar", "git", "https://github.com/rsc/foo/bar"}, + }, + }, + { + ` + `, + []metaImport{ + {"foo/bar", "git", "https://github.com/rsc/foo/bar"}, + }, + }, { ` @@ -127,6 +141,21 @@ var parseMetaGoImportsTests = []struct { `, []metaImport{{"foo/bar", "git", "https://github.com/rsc/foo/bar"}}, }, + { + ``, + []metaImport{{"foo/bar", "git", "https://github.com/rsc/foo/bar"}}, + }, + { + // XML doesn't like
. + `Page Not Found
DRAFT
`, + []metaImport{{"chitin.io/chitin", "git", "https://github.com/chitin-io/chitin"}}, + }, + { + ` + + `, + []metaImport{{"myitcv.io", "git", "https://github.com/myitcv/x"}}, + }, } func TestParseMetaGoImports(t *testing.T) {