mirror of
https://github.com/golang/go
synced 2024-11-05 18:36:08 +00:00
net/url: Rename ParseWithReference to ParseWithFragment.
Updates #2946. R=golang-dev, r, r CC=golang-dev https://golang.org/cl/5671061
This commit is contained in:
parent
34de45c435
commit
8342793e7b
6 changed files with 97 additions and 12 deletions
|
@ -1779,6 +1779,10 @@ A new <a href="/pkg/net/url/#URL.RequestURI"><code>RequestURI</code></a> method
|
|||
added to <code>URL</code>.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The <code>ParseWithReference</code> function has been renamed to <code>ParseWithFragment</code>.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<em>Updating</em>:
|
||||
Code that uses the old fields will fail to compile and must be updated by hand.
|
||||
|
|
|
@ -1669,6 +1669,10 @@ A new <a href="/pkg/net/url/#URL.RequestURI"><code>RequestURI</code></a> method
|
|||
added to <code>URL</code>.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The <code>ParseWithReference</code> function has been renamed to <code>ParseWithFragment</code>.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<em>Updating</em>:
|
||||
Code that uses the old fields will fail to compile and must be updated by hand.
|
||||
|
|
46
src/cmd/fix/url2.go
Normal file
46
src/cmd/fix/url2.go
Normal file
|
@ -0,0 +1,46 @@
|
|||
// Copyright 2011 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package main
|
||||
|
||||
import "go/ast"
|
||||
|
||||
func init() {
|
||||
register(url2Fix)
|
||||
}
|
||||
|
||||
var url2Fix = fix{
|
||||
"url2",
|
||||
"2012-02-16",
|
||||
url2,
|
||||
`Rename some functions in net/url.
|
||||
|
||||
http://codereview.appspot.com/5671061
|
||||
`,
|
||||
}
|
||||
|
||||
func url2(f *ast.File) bool {
|
||||
if !imports(f, "net/url") {
|
||||
return false
|
||||
}
|
||||
|
||||
fixed := false
|
||||
|
||||
walk(f, func(n interface{}) {
|
||||
// Rename functions and methods.
|
||||
sel, ok := n.(*ast.SelectorExpr)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if !isTopName(sel.X, "url") {
|
||||
return
|
||||
}
|
||||
if sel.Sel.Name == "ParseWithReference" {
|
||||
sel.Sel.Name = "ParseWithFragment"
|
||||
fixed = true
|
||||
}
|
||||
})
|
||||
|
||||
return fixed
|
||||
}
|
31
src/cmd/fix/url2_test.go
Normal file
31
src/cmd/fix/url2_test.go
Normal file
|
@ -0,0 +1,31 @@
|
|||
// Copyright 2011 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package main
|
||||
|
||||
func init() {
|
||||
addTestCases(url2Tests, url2)
|
||||
}
|
||||
|
||||
var url2Tests = []testCase{
|
||||
{
|
||||
Name: "url2.0",
|
||||
In: `package main
|
||||
|
||||
import "net/url"
|
||||
|
||||
func f() {
|
||||
url.ParseWithReference("foo")
|
||||
}
|
||||
`,
|
||||
Out: `package main
|
||||
|
||||
import "net/url"
|
||||
|
||||
func f() {
|
||||
url.ParseWithFragment("foo")
|
||||
}
|
||||
`,
|
||||
},
|
||||
}
|
|
@ -415,18 +415,18 @@ func parseAuthority(authority string) (user *Userinfo, host string, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
// ParseWithReference is like Parse but allows a trailing #fragment.
|
||||
func ParseWithReference(rawurlref string) (url *URL, err error) {
|
||||
// ParseWithFragment is like Parse but allows a trailing #fragment.
|
||||
func ParseWithFragment(rawurl string) (url *URL, err error) {
|
||||
// Cut off #frag
|
||||
rawurl, frag := split(rawurlref, '#', true)
|
||||
if url, err = Parse(rawurl); err != nil {
|
||||
u, frag := split(rawurl, '#', true)
|
||||
if url, err = Parse(u); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if frag == "" {
|
||||
return url, nil
|
||||
}
|
||||
if url.Fragment, err = unescape(frag, encodeFragment); err != nil {
|
||||
return nil, &Error{"parse", rawurlref, err}
|
||||
return nil, &Error{"parse", rawurl, err}
|
||||
}
|
||||
return url, nil
|
||||
}
|
||||
|
|
|
@ -260,9 +260,9 @@ func TestParse(t *testing.T) {
|
|||
DoTest(t, Parse, "Parse", urlnofragtests)
|
||||
}
|
||||
|
||||
func TestParseWithReference(t *testing.T) {
|
||||
DoTest(t, ParseWithReference, "ParseWithReference", urltests)
|
||||
DoTest(t, ParseWithReference, "ParseWithReference", urlfragtests)
|
||||
func TestParseWithFragment(t *testing.T) {
|
||||
DoTest(t, ParseWithFragment, "ParseWithFragment", urltests)
|
||||
DoTest(t, ParseWithFragment, "ParseWithFragment", urlfragtests)
|
||||
}
|
||||
|
||||
const pathThatLooksSchemeRelative = "//not.a.user@not.a.host/just/a/path"
|
||||
|
@ -320,8 +320,8 @@ func DoTestString(t *testing.T, parse func(string) (*URL, error), name string, t
|
|||
func TestURLString(t *testing.T) {
|
||||
DoTestString(t, Parse, "Parse", urltests)
|
||||
DoTestString(t, Parse, "Parse", urlnofragtests)
|
||||
DoTestString(t, ParseWithReference, "ParseWithReference", urltests)
|
||||
DoTestString(t, ParseWithReference, "ParseWithReference", urlfragtests)
|
||||
DoTestString(t, ParseWithFragment, "ParseWithFragment", urltests)
|
||||
DoTestString(t, ParseWithFragment, "ParseWithFragment", urlfragtests)
|
||||
}
|
||||
|
||||
type EscapeTest struct {
|
||||
|
@ -538,7 +538,7 @@ var resolveReferenceTests = []struct {
|
|||
|
||||
func TestResolveReference(t *testing.T) {
|
||||
mustParse := func(url string) *URL {
|
||||
u, err := ParseWithReference(url)
|
||||
u, err := ParseWithFragment(url)
|
||||
if err != nil {
|
||||
t.Fatalf("Expected URL to parse: %q, got error: %v", url, err)
|
||||
}
|
||||
|
@ -589,7 +589,7 @@ func TestResolveReference(t *testing.T) {
|
|||
|
||||
func TestResolveReferenceOpaque(t *testing.T) {
|
||||
mustParse := func(url string) *URL {
|
||||
u, err := ParseWithReference(url)
|
||||
u, err := ParseWithFragment(url)
|
||||
if err != nil {
|
||||
t.Fatalf("Expected URL to parse: %q, got error: %v", url, err)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue