@@ -45,6 +45,35 @@ fxdriver.proxy.ProxyConfig;
45
45
fxdriver . proxy . LOG_ = fxdriver . logging . getLogger ( 'fxdriver.proxy' ) ;
46
46
47
47
48
+ /**
49
+ * Splits a hostport, e.g., 'www.example.com:80' into host and port.
50
+ * @param {string } hostport A hostport.
51
+ * @return {{host: string, port: ?number} } A host and port. If no port is
52
+ * present in the argument hostport, port is null.
53
+ * @private
54
+ */
55
+ fxdriver . proxy . splitHostPort_ = function ( hostport ) {
56
+ var colonIndex = hostport . lastIndexOf ( ':' ) ;
57
+ if ( colonIndex < 0 ) {
58
+ return { host : hostport , port : null } ;
59
+ }
60
+ var secondColonIndex = hostport . indexOf ( ':' ) ;
61
+ if ( secondColonIndex != colonIndex && ! hostport . includes ( '[' ) ) {
62
+ // The hostport contains multiple colons, but no part of it is bracketed,
63
+ // e.g., '2001:4860:4860::8888'. Treat it as an IPv6 literal with no port.
64
+ return { host : hostport , port : null } ;
65
+ }
66
+
67
+ var host = hostport . slice ( 0 , colonIndex ) ;
68
+ // Strip brackets from bracketed IPv6 hosts, e.g., '[::1]'.
69
+ if ( host . startsWith ( '[' ) && host . endsWith ( ']' ) ) {
70
+ host = host . slice ( 1 , - 1 ) ;
71
+ }
72
+ var portStr = hostport . slice ( colonIndex + 1 ) ;
73
+ return { host : host , port : parseInt ( portStr , 10 ) } ;
74
+ } ;
75
+
76
+
48
77
/**
49
78
* Set a specific proxy preference.
50
79
*
@@ -57,10 +86,12 @@ fxdriver.proxy.setProxyPreference_ = function(prefs, type, setting) {
57
86
if ( ! setting ) {
58
87
return ;
59
88
}
60
- var hostPort = setting . split ( ':' ) ;
61
- prefs . setCharPref ( 'network.proxy.' + type , hostPort [ 0 ] ) ;
62
- if ( hostPort . length > 1 ) {
63
- prefs . setIntPref ( 'network.proxy.' + type + '_port' , parseInt ( hostPort [ 1 ] ) ) ;
89
+ var hostAndPort = fxdriver . proxy . splitHostPort_ ( setting ) ;
90
+ var host = hostAndPort . host ;
91
+ var port = hostAndPort . port ;
92
+ prefs . setCharPref ( 'network.proxy.' + type , host ) ;
93
+ if ( port != null ) {
94
+ prefs . setIntPref ( 'network.proxy.' + type + '_port' , port ) ;
64
95
}
65
96
} ;
66
97
0 commit comments