go.tools/go/vcs: apply fix to issue 5801.
No semantic difference from https://golang.org/cl/12343043/ R=bradfitz CC=golang-dev https://golang.org/cl/13383044
This commit is contained in:
parent
65f2ef9ae3
commit
95e4181bb5
|
@ -6,17 +6,35 @@ package vcs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// charsetReader returns a reader for the given charset. Currently
|
||||||
|
// it only supports UTF-8 and ASCII. Otherwise, it returns a meaningful
|
||||||
|
// error which is printed by go get, so the user can find why the package
|
||||||
|
// wasn't downloaded if the encoding is not supported. Note that, in
|
||||||
|
// order to reduce potential errors, ASCII is treated as UTF-8 (i.e. characters
|
||||||
|
// greater than 0x7f are not rejected).
|
||||||
|
func charsetReader(charset string, input io.Reader) (io.Reader, error) {
|
||||||
|
switch strings.ToLower(charset) {
|
||||||
|
case "ascii":
|
||||||
|
return input, nil
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("can't decode XML document using charset %q", charset)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// parseMetaGoImports returns meta imports from the HTML in r.
|
// parseMetaGoImports returns meta imports from the HTML in r.
|
||||||
// Parsing ends at the end of the <head> section or the beginning of the <body>.
|
// Parsing ends at the end of the <head> section or the beginning of the <body>.
|
||||||
func parseMetaGoImports(r io.Reader) (imports []metaImport) {
|
func parseMetaGoImports(r io.Reader) (imports []metaImport, err error) {
|
||||||
d := xml.NewDecoder(r)
|
d := xml.NewDecoder(r)
|
||||||
|
d.CharsetReader = charsetReader
|
||||||
d.Strict = false
|
d.Strict = false
|
||||||
|
var t xml.Token
|
||||||
for {
|
for {
|
||||||
t, err := d.Token()
|
t, err = d.Token()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -492,7 +492,11 @@ func RepoRootForImportDynamic(importPath string, verbose bool) (*RepoRoot, error
|
||||||
return nil, fmt.Errorf("http/https fetch: %v", err)
|
return nil, fmt.Errorf("http/https fetch: %v", err)
|
||||||
}
|
}
|
||||||
defer body.Close()
|
defer body.Close()
|
||||||
metaImport, err := matchGoImport(parseMetaGoImports(body), importPath)
|
imports, err := parseMetaGoImports(body)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("parsing %s: %v", importPath, err)
|
||||||
|
}
|
||||||
|
metaImport, err := matchGoImport(imports, importPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err != errNoMatch {
|
if err != errNoMatch {
|
||||||
return nil, fmt.Errorf("parse %s: %v", urlStr, err)
|
return nil, fmt.Errorf("parse %s: %v", urlStr, err)
|
||||||
|
@ -517,7 +521,10 @@ func RepoRootForImportDynamic(importPath string, verbose bool) (*RepoRoot, error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("fetch %s: %v", urlStr, err)
|
return nil, fmt.Errorf("fetch %s: %v", urlStr, err)
|
||||||
}
|
}
|
||||||
imports := parseMetaGoImports(body)
|
imports, err := parseMetaGoImports(body)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("parsing %s: %v", importPath, err)
|
||||||
|
}
|
||||||
if len(imports) == 0 {
|
if len(imports) == 0 {
|
||||||
return nil, fmt.Errorf("fetch %s: no go-import meta tag", urlStr)
|
return nil, fmt.Errorf("fetch %s: no go-import meta tag", urlStr)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue