]> Cypherpunks repositories - gostls13.git/commitdiff
URL should have an empty Scheme if there is an invalid character (i.e.
authorJacob Baskin <jbaskin@google.com>
Tue, 16 Jun 2009 20:23:42 +0000 (13:23 -0700)
committerJacob Baskin <jbaskin@google.com>
Tue, 16 Jun 2009 20:23:42 +0000 (13:23 -0700)
not [a-zA-Z0-9+-.]) before there is a ":".

This is particularly helpful in the erroneous-but-relatively-common
case of relative URLs containing an unescaped colon in the query
string--see the added test for an example.

R=rsc
APPROVED=rsc
DELTA=15  (15 added, 0 deleted, 0 changed)
OCL=30354
CL=30356

src/pkg/http/url.go
src/pkg/http/url_test.go

index 0325b04eedd56cc3aecc3fa5b3284f3323d7dee9..bd2bfcf9368bdb9f84769dead79f6bc55b234bd6 100644 (file)
@@ -180,6 +180,10 @@ func getscheme(rawurl string) (scheme, path string, err os.Error) {
                                return "", "", BadURL{"missing protocol scheme"}
                        }
                        return rawurl[0:i], rawurl[i+1:len(rawurl)], nil
+               default:
+                       // we have encountered an invalid character,
+                       // so there is no valid scheme
+                       return "", rawurl, nil
                }
        }
        return "", rawurl, nil
index 8d8fabad5f903cf928dea9ac02db53d3656989d9..ea05ed3e8352d31180be23b7a500ccab8bb311e1 100644 (file)
@@ -134,6 +134,17 @@ var urltests = []URLTest {
                },
                ""
        },
+       // unescaped :// in query should not create a scheme
+       URLTest{
+               "/foo?query=http://bad",
+               &URL{
+                       "/foo?query=http://bad",
+                       "", "/foo?query=http://bad",
+                       "", "", "",
+                       "/foo", "query=http://bad", ""
+               },
+               ""
+       },
 }
 
 var urlnofragtests = []URLTest {