diff --git a/lib/agent.js b/lib/agent.js index 7ddb8fca..6697e3a2 100644 --- a/lib/agent.js +++ b/lib/agent.js @@ -25,7 +25,7 @@ module.exports = function () { ? tunnelAgent.httpsOverHttps : tunnelAgent.httpsOverHttp; const proxyAuth = proxy.username && proxy.password - ? `${proxy.username}:${proxy.password}` + ? `${decodeURIComponent(proxy.username)}:${decodeURIComponent(proxy.password)}` : null; return tunnel({ proxy: { diff --git a/test/unit/agent.js b/test/unit/agent.js index a49e0ed6..c2419339 100644 --- a/test/unit/agent.js +++ b/test/unit/agent.js @@ -19,6 +19,17 @@ describe('HTTP agent', function () { assert.strictEqual(443, proxy.defaultPort); }); + it('HTTPS proxy with auth from HTTPS_PROXY using credentials containing special characters', function () { + process.env.HTTPS_PROXY = 'https://user,:pass=@secure:123'; + const proxy = agent(); + delete process.env.HTTPS_PROXY; + assert.strictEqual('object', typeof proxy); + assert.strictEqual('secure', proxy.options.proxy.host); + assert.strictEqual(123, proxy.options.proxy.port); + assert.strictEqual('user,:pass=', proxy.options.proxy.proxyAuth); + assert.strictEqual(443, proxy.defaultPort); + }); + it('HTTP proxy without auth from npm_config_proxy', function () { process.env.npm_config_proxy = 'http://plaintext:456'; const proxy = agent();