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.
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.
--- /dev/null
+// 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
+}
--- /dev/null
+// 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")
+}
+`,
+ },
+}
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
}
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"
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 {
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)
}
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)
}