File tree Expand file tree Collapse file tree 2 files changed +33
-3
lines changed Expand file tree Collapse file tree 2 files changed +33
-3
lines changed Original file line number Diff line number Diff line change @@ -46,7 +46,7 @@ func DecodeRemote(s string) (*Remote, error) {
4646 s = strings .TrimPrefix (s , revPrefix )
4747 reverse = true
4848 }
49- parts := strings . Split ( s , ":" )
49+ parts := regexp . MustCompile ( `(\[[^\[\]]+\]|[^\[\]:]+):?` ). FindAllStringSubmatch ( s , - 1 )
5050 if len (parts ) <= 0 || len (parts ) >= 5 {
5151 return nil , errors .New ("Invalid remote" )
5252 }
@@ -55,7 +55,7 @@ func DecodeRemote(s string) (*Remote, error) {
5555 //then to set 'local' fields second (allows the 'remote' side
5656 //to provide the defaults)
5757 for i := len (parts ) - 1 ; i >= 0 ; i -- {
58- p := parts [i ]
58+ p := parts [i ][ 1 ]
5959 //remote portion is socks?
6060 if i == len (parts )- 1 && p == "socks" {
6161 r .Socks = true
@@ -144,7 +144,7 @@ func isPort(s string) bool {
144144}
145145
146146func isHost (s string ) bool {
147- _ , err := url .Parse (s )
147+ _ , err := url .Parse ("//" + s )
148148 if err != nil {
149149 return false
150150 }
Original file line number Diff line number Diff line change @@ -40,6 +40,15 @@ func TestRemoteDecode(t *testing.T) {
4040 },
4141 "R:0.0.0.0:80:google.com:80" ,
4242 },
43+ {
44+ "示例網站.com:80" ,
45+ Remote {
46+ LocalPort : "80" ,
47+ RemoteHost : "示例網站.com" ,
48+ RemotePort : "80" ,
49+ },
50+ "0.0.0.0:80:示例網站.com:80" ,
51+ },
4352 {
4453 "socks" ,
4554 Remote {
@@ -81,6 +90,27 @@ func TestRemoteDecode(t *testing.T) {
8190 },
8291 "localhost:5353:1.1.1.1:53/udp" ,
8392 },
93+ {
94+ "[::1]:8080:google.com:80" ,
95+ Remote {
96+ LocalHost : "[::1]" ,
97+ LocalPort : "8080" ,
98+ RemoteHost : "google.com" ,
99+ RemotePort : "80" ,
100+ },
101+ "[::1]:8080:google.com:80" ,
102+ },
103+ {
104+ "R:[::]:3000:[::1]:3000" ,
105+ Remote {
106+ LocalHost : "[::]" ,
107+ LocalPort : "3000" ,
108+ RemoteHost : "[::1]" ,
109+ RemotePort : "3000" ,
110+ Reverse : true ,
111+ },
112+ "R:[::]:3000:[::1]:3000" ,
113+ },
84114 } {
85115 //expected defaults
86116 expected := test .Output
You can’t perform that action at this time.
0 commit comments