File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -446,6 +446,9 @@ func parseHost(host []byte) ([]byte, error) {
446
446
return append (host1 , append (host2 , host3 ... )... ), nil
447
447
}
448
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 )
451
+ }
449
452
colonPort := host [i :]
450
453
if ! validOptionalPort (colonPort ) {
451
454
return nil , fmt .Errorf ("invalid port %q after host" , colonPort )
Original file line number Diff line number Diff line change @@ -145,6 +145,27 @@ func TestURIRejectInvalidScheme(t *testing.T) {
145
145
}
146
146
}
147
147
148
+ func TestURIRejectMultiplePorts (t * testing.T ) {
149
+ t .Parallel ()
150
+
151
+ testcases := []string {
152
+ "http://192.168.1.1:1111:2222/" ,
153
+ "http://example.com:80:8080/" ,
154
+ }
155
+
156
+ for _ , raw := range testcases {
157
+ var u URI
158
+ if err := u .Parse (nil , []byte (raw )); err == nil {
159
+ t .Fatalf ("expected Parse to fail for %q" , raw )
160
+ }
161
+ }
162
+
163
+ var valid URI
164
+ if err := valid .Parse (nil , []byte ("http://192.168.1.1:1111/" )); err != nil {
165
+ t .Fatalf ("unexpected error for valid uri: %v" , err )
166
+ }
167
+ }
168
+
148
169
func TestURIUpdate (t * testing.T ) {
149
170
t .Parallel ()
150
171
You can’t perform that action at this time.
0 commit comments