@@ -681,12 +681,6 @@ var parseRequestURLTests = []struct {
681
681
// RFC 6874.
682
682
{"http://[fe80::1%en0]/" , false },
683
683
{"http://[fe80::1%en0]:8080/" , false },
684
-
685
- // Testing valid and invalid URL schemes
686
- {"ahttp://example.com" , true },
687
- {" http://example.com" , false },
688
- {"+http://example.com" , false },
689
- {"1http://example.com" , false },
690
684
}
691
685
692
686
func TestParseRequestURI (t * testing.T ) {
@@ -1873,3 +1867,27 @@ func BenchmarkPathUnescape(b *testing.B) {
1873
1867
})
1874
1868
}
1875
1869
}
1870
+
1871
+ var urlSchemeValidTests = []struct {
1872
+ url string
1873
+ expectedValid bool
1874
+ }{
1875
+ {"ahttp://example.com" , true },
1876
+ {" http://example.com" , false },
1877
+ {"+http://example.com" , false },
1878
+ {"example.com" , false },
1879
+ }
1880
+
1881
+ func TestValidUrlSchemes (t * testing.T ) {
1882
+ for _ , test := range urlSchemeValidTests {
1883
+ _ , err := ParseRequestURI (test .url )
1884
+ if test .expectedValid && err != nil {
1885
+ t .Errorf ("ParseRequestURI(%q) gave err %v; want no error" , test .url , err )
1886
+ } else if ! test .expectedValid && err == nil {
1887
+ t .Errorf ("ParseRequestURI(%q) gave nil error; want some error" , test .url )
1888
+ } else if ! test .expectedValid && err != nil && ! strings .ContainsAny (err .Error (), "Url scheme has invalid character!!" ) {
1889
+ //t.Errorf("Error was %v", err.Error())
1890
+ t .Errorf ("ParseRequestURI(%q) gave error %v; want Invalid scheme error" , test .url , err )
1891
+ }
1892
+ }
1893
+ }
0 commit comments