Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit e579c06

Browse files
committed
Install: Improves code to get proxy.
* Credit: @xzyfer. * Addresses #588.
1 parent a11fafd commit e579c06

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

scripts/install.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,11 @@ function download(url, dest, cb) {
4343
*/
4444

4545
function getProxy() {
46-
var result;
47-
48-
['https-proxy', 'proxy', 'http-proxy'].map(function(config) {
46+
var result = ['https-proxy', 'proxy', 'http-proxy'].filter(function(config) {
4947
var proxy = exec('npm config get ' + config, {silent: true});
50-
var output = proxy.output.trim();
5148

52-
if (proxy.code === 0 && output !== 'undefined' && output !== 'null') {
53-
result = proxy.output;
54-
return;
55-
}
56-
});
49+
return proxy.code === 0 && validateProxyUrl(proxy.output.trim());
50+
})[0];
5751

5852
if (result) {
5953
return result;
@@ -63,6 +57,23 @@ function getProxy() {
6357
return env.HTTPS_PROXY || env.https_proxy || env.HTTP_PROXY || env.http_proxy;
6458
}
6559

60+
/**
61+
* Validates Proxy URL
62+
*
63+
* @param {String} url
64+
* @api private
65+
*/
66+
67+
function validateProxyUrl(url) {
68+
if (/\n/.test(url)) {
69+
url = url.replace(/\r?\n+/, '\n').split('\n')[8];
70+
}
71+
72+
return url !== 'null' &&
73+
url !== 'undefined' &&
74+
url === require('url').parse(url);
75+
}
76+
6677
/**
6778
* Check if binaries exists
6879
*

0 commit comments

Comments
 (0)