From 08243ce2e3129997461bfe0881983876a304e3a7 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 18 Oct 2013 11:35:09 +0200 Subject: [PATCH] Fix handling of urlencoded user and password in proxy urls, fixes #2339 --- src/Composer/Util/StreamContextFactory.php | 4 ++-- tests/Composer/Test/Util/StreamContextFactoryTest.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Composer/Util/StreamContextFactory.php b/src/Composer/Util/StreamContextFactory.php index 892016674..9ed131b02 100644 --- a/src/Composer/Util/StreamContextFactory.php +++ b/src/Composer/Util/StreamContextFactory.php @@ -91,9 +91,9 @@ final class StreamContextFactory } if (isset($proxy['user'])) { - $auth = $proxy['user']; + $auth = urldecode($proxy['user']); if (isset($proxy['pass'])) { - $auth .= ':' . $proxy['pass']; + $auth .= ':' . urldecode($proxy['pass']); } $auth = base64_encode($auth); diff --git a/tests/Composer/Test/Util/StreamContextFactoryTest.php b/tests/Composer/Test/Util/StreamContextFactoryTest.php index 9e1bae090..b0923e6df 100644 --- a/tests/Composer/Test/Util/StreamContextFactoryTest.php +++ b/tests/Composer/Test/Util/StreamContextFactoryTest.php @@ -59,7 +59,7 @@ class StreamContextFactoryTest extends \PHPUnit_Framework_TestCase public function testHttpProxy() { - $_SERVER['http_proxy'] = 'http://username:password@proxyserver.net:3128/'; + $_SERVER['http_proxy'] = 'http://username:p%40ssword@proxyserver.net:3128/'; $_SERVER['HTTP_PROXY'] = 'http://proxyserver/'; $context = StreamContextFactory::getContext('http://example.org', array('http' => array('method' => 'GET'))); @@ -69,7 +69,7 @@ class StreamContextFactoryTest extends \PHPUnit_Framework_TestCase 'proxy' => 'tcp://proxyserver.net:3128', 'request_fulluri' => true, 'method' => 'GET', - 'header' => array("Proxy-Authorization: Basic " . base64_encode('username:password')), + 'header' => array("Proxy-Authorization: Basic " . base64_encode('username:p@ssword')), 'max_redirects' => 20, 'follow_location' => 1, )), $options);