go/vcs: fix bug in remote package discovery
The parser was assuming it would find <body> or </head>. If the entire response is just <meta> tags, it finds EOF and treats that as an error. It's not. This is the same change as in https://golang.org/cl/68520044. Fixes #9556. Change-Id: If51ed36e7364c15788311039caf8323eb5fe9a6c Reviewed-on: https://go-review.googlesource.com/2650 Reviewed-by: Minux Ma <minux@golang.org>
This commit is contained in:
parent
9468e480c8
commit
c10e262955
|
@ -36,6 +36,9 @@ func parseMetaGoImports(r io.Reader) (imports []metaImport, err error) {
|
||||||
for {
|
for {
|
||||||
t, err = d.Token()
|
t, err = d.Token()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if err == io.EOF {
|
||||||
|
err = nil
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if e, ok := t.(xml.StartElement); ok && strings.EqualFold(e.Name.Local, "body") {
|
if e, ok := t.(xml.StartElement); ok && strings.EqualFold(e.Name.Local, "body") {
|
||||||
|
|
|
@ -8,6 +8,8 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"reflect"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -84,3 +86,45 @@ func TestFromDir(t *testing.T) {
|
||||||
os.RemoveAll(test.path)
|
os.RemoveAll(test.path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var parseMetaGoImportsTests = []struct {
|
||||||
|
in string
|
||||||
|
out []metaImport
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
`<meta name="go-import" content="foo/bar git https://github.com/rsc/foo/bar">`,
|
||||||
|
[]metaImport{{"foo/bar", "git", "https://github.com/rsc/foo/bar"}},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
`<meta name="go-import" content="foo/bar git https://github.com/rsc/foo/bar">
|
||||||
|
<meta name="go-import" content="baz/quux git http://github.com/rsc/baz/quux">`,
|
||||||
|
[]metaImport{
|
||||||
|
{"foo/bar", "git", "https://github.com/rsc/foo/bar"},
|
||||||
|
{"baz/quux", "git", "http://github.com/rsc/baz/quux"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
`<head>
|
||||||
|
<meta name="go-import" content="foo/bar git https://github.com/rsc/foo/bar">
|
||||||
|
</head>`,
|
||||||
|
[]metaImport{{"foo/bar", "git", "https://github.com/rsc/foo/bar"}},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
`<meta name="go-import" content="foo/bar git https://github.com/rsc/foo/bar">
|
||||||
|
<body>`,
|
||||||
|
[]metaImport{{"foo/bar", "git", "https://github.com/rsc/foo/bar"}},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestParseMetaGoImports(t *testing.T) {
|
||||||
|
for i, tt := range parseMetaGoImportsTests {
|
||||||
|
out, err := parseMetaGoImports(strings.NewReader(tt.in))
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("test#%d: %v", i, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if !reflect.DeepEqual(out, tt.out) {
|
||||||
|
t.Errorf("test#%d:\n\thave %q\n\twant %q", i, out, tt.out)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue