Browse Source

Fix handling of urlencoded user and password in proxy urls, fixes #2339

Jordi Boggiano 11 years ago
parent
commit
08243ce2e3

+ 2 - 2
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);
 

+ 2 - 2
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);