@@ -22,6 +22,7 @@ import (
22
22
"context"
23
23
"io"
24
24
"net"
25
+ "net/url"
25
26
"runtime"
26
27
"strings"
27
28
"sync"
@@ -746,21 +747,25 @@ func Stop(ctx context.Context, protoAddr string) error {
746
747
}
747
748
748
749
func parseProtoAddr (protoAddr string ) (string , string , error ) {
749
- protoAddr = strings .ToLower (protoAddr )
750
- if strings .Count (protoAddr , "://" ) != 1 {
750
+ // Percent-encode "%" in the address to avoid url.Parse error.
751
+ // For example: udp://[ff02::3%lo0]:9991
752
+ protoAddr = strings .ReplaceAll (protoAddr , "%" , "%25" )
753
+
754
+ u , err := url .Parse (protoAddr )
755
+ if err != nil {
756
+ return "" , "" , err
757
+ }
758
+
759
+ if u .Scheme == "" || u .Host == "" || u .Path != "" {
751
760
return "" , "" , errorx .ErrInvalidNetworkAddress
752
761
}
753
- pair := strings .SplitN (protoAddr , "://" , 2 )
754
- proto , addr := pair [0 ], pair [1 ]
755
- switch proto {
762
+ switch u .Scheme {
756
763
case "tcp" , "tcp4" , "tcp6" , "udp" , "udp4" , "udp6" , "unix" :
757
764
default :
758
765
return "" , "" , errorx .ErrUnsupportedProtocol
759
766
}
760
- if addr == "" {
761
- return "" , "" , errorx .ErrInvalidNetworkAddress
762
- }
763
- return proto , addr , nil
767
+
768
+ return u .Scheme , u .Host , nil
764
769
}
765
770
766
771
func determineEventLoops (opts * Options ) int {
0 commit comments