• Russ Cox's avatar
    net/url: do not percent-encode valid host characters · e8be9a17
    Russ Cox authored
    The code in question was added as part of allowing zone identifiers
    in IPv6 literals like http://[ipv6%zone]:port/foo, in golang.org/cl/2431.
    
    The old condition makes no sense. It refers to §3.2.1, which is the wrong section
    of the RFC, it excludes all the sub-delims, which §3.2.2 (the right section)
    makes clear are valid, and it allows ':', which is not actually valid,
    without an explanation as to why (because we keep :port in the Host field
    of the URL struct).
    
    The new condition allows all the sub-delims, as specified in RFC 3986,
    plus the additional characters [ ] : seen in IP address literals and :port suffixes,
    which we also keep in the Host field.
    
    This allows mysql://a,b,c/path to continue to parse, as it did in Go 1.4 and earlier.
    
    This CL does not break any existing tests, suggesting the over-conservative
    behavior was not intended and perhaps not realized.
    
    It is especially important not to over-escape the host field, because
    Go does not unescape the host field during parsing: it rejects any
    host field containing % characters.
    
    Fixes #12036.
    
    Change-Id: Iccbe4985957b3dc58b6dfb5dcb5b63a51a6feefb
    Reviewed-on: https://go-review.googlesource.com/13254Reviewed-by: default avatarAndrew Gerrand <adg@golang.org>
    Reviewed-by: default avatarMikio Hara <mikioh.mikioh@gmail.com>
    e8be9a17
url_test.go 28.8 KB