Commit 8342793e authored by David Symonds's avatar David Symonds

net/url: Rename ParseWithReference to ParseWithFragment.

Updates #2946.

R=golang-dev, r, r
CC=golang-dev
https://golang.org/cl/5671061
parent 34de45c4
...@@ -1779,6 +1779,10 @@ A new <a href="/pkg/net/url/#URL.RequestURI"><code>RequestURI</code></a> method ...@@ -1779,6 +1779,10 @@ A new <a href="/pkg/net/url/#URL.RequestURI"><code>RequestURI</code></a> method
added to <code>URL</code>. added to <code>URL</code>.
</p> </p>
<p>
The <code>ParseWithReference</code> function has been renamed to <code>ParseWithFragment</code>.
</p>
<p> <p>
<em>Updating</em>: <em>Updating</em>:
Code that uses the old fields will fail to compile and must be updated by hand. 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 ...@@ -1669,6 +1669,10 @@ A new <a href="/pkg/net/url/#URL.RequestURI"><code>RequestURI</code></a> method
added to <code>URL</code>. added to <code>URL</code>.
</p> </p>
<p>
The <code>ParseWithReference</code> function has been renamed to <code>ParseWithFragment</code>.
</p>
<p> <p>
<em>Updating</em>: <em>Updating</em>:
Code that uses the old fields will fail to compile and must be updated by hand. Code that uses the old fields will fail to compile and must be updated by hand.
......
// 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
}
// 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) { ...@@ -415,18 +415,18 @@ func parseAuthority(authority string) (user *Userinfo, host string, err error) {
return return
} }
// ParseWithReference is like Parse but allows a trailing #fragment. // ParseWithFragment is like Parse but allows a trailing #fragment.
func ParseWithReference(rawurlref string) (url *URL, err error) { func ParseWithFragment(rawurl string) (url *URL, err error) {
// Cut off #frag // Cut off #frag
rawurl, frag := split(rawurlref, '#', true) u, frag := split(rawurl, '#', true)
if url, err = Parse(rawurl); err != nil { if url, err = Parse(u); err != nil {
return nil, err return nil, err
} }
if frag == "" { if frag == "" {
return url, nil return url, nil
} }
if url.Fragment, err = unescape(frag, encodeFragment); err != 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 return url, nil
} }
......
...@@ -260,9 +260,9 @@ func TestParse(t *testing.T) { ...@@ -260,9 +260,9 @@ func TestParse(t *testing.T) {
DoTest(t, Parse, "Parse", urlnofragtests) DoTest(t, Parse, "Parse", urlnofragtests)
} }
func TestParseWithReference(t *testing.T) { func TestParseWithFragment(t *testing.T) {
DoTest(t, ParseWithReference, "ParseWithReference", urltests) DoTest(t, ParseWithFragment, "ParseWithFragment", urltests)
DoTest(t, ParseWithReference, "ParseWithReference", urlfragtests) DoTest(t, ParseWithFragment, "ParseWithFragment", urlfragtests)
} }
const pathThatLooksSchemeRelative = "//not.a.user@not.a.host/just/a/path" 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 ...@@ -320,8 +320,8 @@ func DoTestString(t *testing.T, parse func(string) (*URL, error), name string, t
func TestURLString(t *testing.T) { func TestURLString(t *testing.T) {
DoTestString(t, Parse, "Parse", urltests) DoTestString(t, Parse, "Parse", urltests)
DoTestString(t, Parse, "Parse", urlnofragtests) DoTestString(t, Parse, "Parse", urlnofragtests)
DoTestString(t, ParseWithReference, "ParseWithReference", urltests) DoTestString(t, ParseWithFragment, "ParseWithFragment", urltests)
DoTestString(t, ParseWithReference, "ParseWithReference", urlfragtests) DoTestString(t, ParseWithFragment, "ParseWithFragment", urlfragtests)
} }
type EscapeTest struct { type EscapeTest struct {
...@@ -538,7 +538,7 @@ var resolveReferenceTests = []struct { ...@@ -538,7 +538,7 @@ var resolveReferenceTests = []struct {
func TestResolveReference(t *testing.T) { func TestResolveReference(t *testing.T) {
mustParse := func(url string) *URL { mustParse := func(url string) *URL {
u, err := ParseWithReference(url) u, err := ParseWithFragment(url)
if err != nil { if err != nil {
t.Fatalf("Expected URL to parse: %q, got error: %v", url, err) t.Fatalf("Expected URL to parse: %q, got error: %v", url, err)
} }
...@@ -589,7 +589,7 @@ func TestResolveReference(t *testing.T) { ...@@ -589,7 +589,7 @@ func TestResolveReference(t *testing.T) {
func TestResolveReferenceOpaque(t *testing.T) { func TestResolveReferenceOpaque(t *testing.T) {
mustParse := func(url string) *URL { mustParse := func(url string) *URL {
u, err := ParseWithReference(url) u, err := ParseWithFragment(url)
if err != nil { if err != nil {
t.Fatalf("Expected URL to parse: %q, got error: %v", url, err) t.Fatalf("Expected URL to parse: %q, got error: %v", url, err)
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment