From: Jacob Baskin Date: Tue, 16 Jun 2009 20:23:42 +0000 (-0700) Subject: URL should have an empty Scheme if there is an invalid character (i.e. X-Git-Tag: weekly.2009-11-06~1393 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=536c2aa6aebc7b89b9c57e09b41985875aa1aa01;p=gostls13.git URL should have an empty Scheme if there is an invalid character (i.e. 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 --- diff --git a/src/pkg/http/url.go b/src/pkg/http/url.go index 0325b04eed..bd2bfcf936 100644 --- a/src/pkg/http/url.go +++ b/src/pkg/http/url.go @@ -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 diff --git a/src/pkg/http/url_test.go b/src/pkg/http/url_test.go index 8d8fabad5f..ea05ed3e83 100644 --- a/src/pkg/http/url_test.go +++ b/src/pkg/http/url_test.go @@ -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 {