File tree 3 files changed +60
-0
lines changed
3 files changed +60
-0
lines changed Original file line number Diff line number Diff line change @@ -353,6 +353,44 @@ var reqWriteTests = []reqWriteTest{
353
353
"Host: \r \n " +
354
354
"User-Agent: Go http package\r \n \r \n " ,
355
355
},
356
+
357
+ // Opaque test #1 from golang.org/issue/4860
358
+ {
359
+ Req : Request {
360
+ Method : "GET" ,
361
+ URL : & url.URL {
362
+ Scheme : "http" ,
363
+ Host : "www.google.com" ,
364
+ Opaque : "/%2F/%2F/" ,
365
+ },
366
+ ProtoMajor : 1 ,
367
+ ProtoMinor : 1 ,
368
+ Header : Header {},
369
+ },
370
+
371
+ WantWrite : "GET /%2F/%2F/ HTTP/1.1\r \n " +
372
+ "Host: www.google.com\r \n " +
373
+ "User-Agent: Go http package\r \n \r \n " ,
374
+ },
375
+
376
+ // Opaque test #2 from golang.org/issue/4860
377
+ {
378
+ Req : Request {
379
+ Method : "GET" ,
380
+ URL : & url.URL {
381
+ Scheme : "http" ,
382
+ Host : "x.google.com" ,
383
+ Opaque : "//y.google.com/%2F/%2F/" ,
384
+ },
385
+ ProtoMajor : 1 ,
386
+ ProtoMinor : 1 ,
387
+ Header : Header {},
388
+ },
389
+
390
+ WantWrite : "GET http://y.google.com/%2F/%2F/ HTTP/1.1\r \n " +
391
+ "Host: x.google.com\r \n " +
392
+ "User-Agent: Go http package\r \n \r \n " ,
393
+ },
356
394
}
357
395
358
396
func TestRequestWrite (t * testing.T ) {
Original file line number Diff line number Diff line change @@ -693,6 +693,10 @@ func (u *URL) RequestURI() string {
693
693
if result == "" {
694
694
result = "/"
695
695
}
696
+ } else {
697
+ if strings .HasPrefix (result , "//" ) {
698
+ result = u .Scheme + ":" + result
699
+ }
696
700
}
697
701
if u .RawQuery != "" {
698
702
result += "?" + u .RawQuery
Original file line number Diff line number Diff line change @@ -798,6 +798,24 @@ var requritests = []RequestURITest{
798
798
},
799
799
"/a%20b" ,
800
800
},
801
+ // golang.org/issue/4860 variant 1
802
+ {
803
+ & URL {
804
+ Scheme : "http" ,
805
+ Host : "example.com" ,
806
+ Opaque : "/%2F/%2F/" ,
807
+ },
808
+ "/%2F/%2F/" ,
809
+ },
810
+ // golang.org/issue/4860 variant 2
811
+ {
812
+ & URL {
813
+ Scheme : "http" ,
814
+ Host : "example.com" ,
815
+ Opaque : "//other.example.com/%2F/%2F/" ,
816
+ },
817
+ "http://other.example.com/%2F/%2F/" ,
818
+ },
801
819
{
802
820
& URL {
803
821
Scheme : "http" ,
You can’t perform that action at this time.
0 commit comments