From c10e262955e9f7bf20aaa801af6ff2dd14674159 Mon Sep 17 00:00:00 2001 From: Dmitri Shuralyov Date: Fri, 9 Jan 2015 23:26:36 -0800 Subject: [PATCH] go/vcs: fix bug in remote package discovery The parser was assuming it would find or . If the entire response is just 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 --- go/vcs/discovery.go | 3 +++ go/vcs/vcs_test.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/go/vcs/discovery.go b/go/vcs/discovery.go index d5c3fc6b..c4b0e3d1 100644 --- a/go/vcs/discovery.go +++ b/go/vcs/discovery.go @@ -36,6 +36,9 @@ func parseMetaGoImports(r io.Reader) (imports []metaImport, err error) { for { t, err = d.Token() if err != nil { + if err == io.EOF { + err = nil + } return } if e, ok := t.(xml.StartElement); ok && strings.EqualFold(e.Name.Local, "body") { diff --git a/go/vcs/vcs_test.go b/go/vcs/vcs_test.go index 0b8dd8c8..226a3e41 100644 --- a/go/vcs/vcs_test.go +++ b/go/vcs/vcs_test.go @@ -8,6 +8,8 @@ import ( "io/ioutil" "os" "path/filepath" + "reflect" + "strings" "testing" ) @@ -84,3 +86,45 @@ func TestFromDir(t *testing.T) { os.RemoveAll(test.path) } } + +var parseMetaGoImportsTests = []struct { + in string + out []metaImport +}{ + { + ``, + []metaImport{{"foo/bar", "git", "https://github.com/rsc/foo/bar"}}, + }, + { + ` + `, + []metaImport{ + {"foo/bar", "git", "https://github.com/rsc/foo/bar"}, + {"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"}}, + }, +} + +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) + } + } +}