File tree Expand file tree Collapse file tree 2 files changed +29
-6
lines changed Expand file tree Collapse file tree 2 files changed +29
-6
lines changed Original file line number Diff line number Diff line change @@ -445,13 +445,20 @@ func parseHost(host []byte) ([]byte, error) {
445445 }
446446 return append (host1 , append (host2 , host3 ... )... ), nil
447447 }
448- } else if i := bytes . LastIndexByte ( host , ':' ); i != - 1 {
449- if bytes .IndexByte (host [: i ] , ': ' ) != - 1 {
450- return nil , fmt .Errorf ("invalid host %q with multiple port delimiters " , host )
448+ } else {
449+ if bytes .IndexByte (host , '[' ) != - 1 || bytes . IndexByte ( host , '] ' ) != - 1 {
450+ return nil , fmt .Errorf ("invalid host %q" , host )
451451 }
452- colonPort := host [i :]
453- if ! validOptionalPort (colonPort ) {
454- return nil , fmt .Errorf ("invalid port %q after host" , colonPort )
452+
453+ if i := bytes .LastIndexByte (host , ':' ); i != - 1 {
454+ if bytes .IndexByte (host [:i ], ':' ) != - 1 {
455+ return nil , fmt .Errorf ("invalid host %q with multiple port delimiters" , host )
456+ }
457+
458+ colonPort := host [i :]
459+ if ! validOptionalPort (colonPort ) {
460+ return nil , fmt .Errorf ("invalid port %q after host" , colonPort )
461+ }
455462 }
456463 }
457464
Original file line number Diff line number Diff line change @@ -203,6 +203,22 @@ func TestURIUpdate(t *testing.T) {
203203 testURIUpdate (t , "http://example.net/" , "//example.com:8080/" , "http://example.com:8080/" )
204204}
205205
206+ func TestURIRejectsMixedBracketHost (t * testing.T ) {
207+ t .Parallel ()
208+
209+ tests := []string {
210+ "http://127.0.0.1[192.168.0.1]/" ,
211+ "http://example.com[fd00::1]/" ,
212+ }
213+
214+ for _ , raw := range tests {
215+ var u URI
216+ if err := u .Parse (nil , []byte (raw )); err == nil {
217+ t .Fatalf ("expected error for %q" , raw )
218+ }
219+ }
220+ }
221+
206222func testURIUpdate (t * testing.T , base , update , result string ) {
207223 var u URI
208224 u .Parse (nil , []byte (base )) //nolint:errcheck
You can’t perform that action at this time.
0 commit comments