1
0
mirror of https://github.com/golang/go synced 2024-11-18 14:54:40 -07:00

cmd/go/internal/get: make the implementation of charsetReader match its comment

The doc comment for charsetReader claims that it supports UTF-8,
but in practice it does not: instead, it is never invoked for UTF-8.

We could update the comment to clarify that fact, but it seems simpler
to change the implementation to match the comment.

Change-Id: I39b11395ccef3feff96480b9294e8f2a232728dd
Reviewed-on: https://go-review.googlesource.com/c/go/+/189777
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
This commit is contained in:
Bryan C. Mills 2019-08-05 14:32:46 -04:00
parent 51be44bfaf
commit 8fb9fa36f5

View File

@ -11,15 +11,15 @@ import (
"strings"
)
// charsetReader returns a reader for the given charset. Currently
// it only supports UTF-8 and ASCII. Otherwise, it returns a meaningful
// charsetReader returns a reader that converts from the given charset to UTF-8.
// 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":
case "utf-8", "ascii":
return input, nil
default:
return nil, fmt.Errorf("can't decode XML document using charset %q", charset)