]> Cypherpunks repositories - gostls13.git/commitdiff
net/url: Rename ParseWithReference to ParseWithFragment.
authorDavid Symonds <dsymonds@golang.org>
Thu, 16 Feb 2012 04:56:03 +0000 (15:56 +1100)
committerDavid Symonds <dsymonds@golang.org>
Thu, 16 Feb 2012 04:56:03 +0000 (15:56 +1100)
Updates #2946.

R=golang-dev, r, r
CC=golang-dev
https://golang.org/cl/5671061

doc/go1.html
doc/go1.tmpl
src/cmd/fix/url2.go [new file with mode: 0644]
src/cmd/fix/url2_test.go [new file with mode: 0644]
src/pkg/net/url/url.go
src/pkg/net/url/url_test.go

index a2cd0456a6e7f7282f001137e2d016b8462426e7..b1f92338da055457846ccc8fa69a1286b7e6e1f5 100644 (file)
@@ -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.
index 90bc9fc7f61826e162ddf1b6e4d5a81b8d137cd2..32b166a8b1120515053b5d7583b335b9ceaa248b 100644 (file)
@@ -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.
diff --git a/src/cmd/fix/url2.go b/src/cmd/fix/url2.go
new file mode 100644 (file)
index 0000000..5fd05ad
--- /dev/null
@@ -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
+}
diff --git a/src/cmd/fix/url2_test.go b/src/cmd/fix/url2_test.go
new file mode 100644 (file)
index 0000000..c68dd88
--- /dev/null
@@ -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")
+}
+`,
+       },
+}
index 834247bd7670be72baaedb9bb2624e333ef3e120..cdfb16ceda2c7479ce906a974bdbc9211e5f8db0 100644 (file)
@@ -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
 }
index 9fe5ff886b7d8be48ef6e366e8a4347be9daf9cb..72d734461f6ffdb0e74c3c86a616accb16866e49 100644 (file)
@@ -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)
                }